Best way to push units away

0 favourites
  • 10 posts
From the Asset Store
Best car suspension with spring effect and very cool terrain generation.
  • Hi guys

    As in all rts like games i need my units to push away from one another, so they dont's stack if not too many. I wanna do it the right way, so the collision between them must be smooth, meaning units should keep certain distance between them, unless they are pushed closer by other units or obstacles.

    I've searched the forums but couldn't find post about this (maybe i dont know how to put it in words), and i think its common matter so maybe a little brainstorming is in order.

    Performance is an issue too, since i plan to have many units per layout.

  • Easiest way: Check distance.

    Actor 1 <= distance(Actor 1.X, Actor 1.Y, Actor 2.X, Actor 2.Y) do Actions;

    You can change actors by families, but only the currently involved objects will be checked and affected.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I have a similar problem I think...

    I have a lot of enemies that converge/follow/move in packs and I'd really like them to space themselves while moving.

    I've tried the solid push out thing but it's a little jumpy. It'd be great to find a solution for it without having to really complicate my enemy movement.

  • You are right TELLES0808, comparing distances seems better than collision checks. I guess an For Each condition is on order so this happens every time units are too close.

    That leaves me with the second problem - the action.

    The units are supposed to gradually push away from each other. Even more it's supposed to have in mind all other units around it. Frankly I have no clue how to achieve this.

    Any ideas?

  • When you want them overlap each other, but not for much time:

    Use the action -> move at angle -> move 200 * dt pixels at angle 180 + (angle(object1.X,object1.Y,object2.X,object2.Y)

    And they will go to the opposite side.

    Else,

    Prevent his movement:

    Check the the distance between each other with the Distance(...) > desired radius

    And do the logic inside this bracket.

  • How would you do this is you had multiple instances of the same object?

  • Put the objects in a Family together. Then do a check for

    distance(Instance.X, Instance.Y, Family.X, Family.Y)

  • Thanks TELLES0808. Looking at it now, at work, where i cant start construct2 to try it out, is hard for me to understand, but i think i got the idea.

    Tonight ill try it out.

  • I think i got it running.

    I had some problems like ome6a1717 said, adressing the units.

    Since the unit is in the family, it seems to detect the distance to itself. So here is what i did

    For each Unit

    distance(Unit.X, Unit.Y, Family.X, Family.Y) < 20

    Unit.UID not= Family.UID

    I got a lot of work on the movement of units, so its really smooth and logical, but i think i got the main idea.

    Thanks

  • Please you can send .capx?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)