1
\$\begingroup\$

I'm looking for a way to have a character, let's call it "root," with a number of other similar characters attached to it. Let's call them children. When the root changes position the children follow and update their own position by their movement patterns.

My objective isn't for the child objects to move 1:1 like the root but to react to it's movement and follow the object loosely. So if the root moves upwards then child follows afterwards with it's own velocity.

Could someone guide me about how to achieve this kind of behavior of objects moving relative to others? About what sort of architecture would fit best for this kind of problem?

\$\endgroup\$
  • \$\begingroup\$ You can try libgdx AI Steering behaviors (such as Pursue or Group behaviors) \$\endgroup\$ – Andrei Yusupau Sep 9 '15 at 15:11
  • 2
    \$\begingroup\$ Your question is slightly badly formed but I do not thing there is reason to close it. What you are looking for is Steering Behaviour or flocking. Rts games use this a lot to move all units within a group. Try to improve the Question quality, ask to reopen and I might even vote it up. \$\endgroup\$ – Madmenyo Sep 11 '15 at 15:23
  • \$\begingroup\$ Fix, now post your comment as answer. \$\endgroup\$ – Jose Gonzalez Sep 11 '15 at 17:18
1
\$\begingroup\$

The A* path finding algorithm can be used by the "Children" to arrive at a certain destination. You could use this algorithm and only use the next node (since the destination's position isn't necessarily static, aka the "Children" follow the "Root" even whilst it is moving). Path finding is expensive as it is. Here, you'd be (re-)running the algorithm whenever the "Root" changes position.

Another approach is to make the "Children" walk in the direction of the "Root", ignoring the fact that there may be barriers in-between them and the "Root". This is a cheap approach but the "Children" may become stuck.

To make the "Children" loosely follow the "Root", only instruct them to follow the "Root" when they are X distance away from them, aka not immediately. Make them stop following when they are less than X distance away from "Root" again, perhaps making them walk Y or 2Y in a random direction, once they get close enough, to make things seem more real and "Loose".

To make the following seem more "Loose", increase the speed of the "Children" slightly when they are further away from the "Root". For example, when the "Root" moves away, the "Children" start slowly following and gradually speed up.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.