How do I keep followers spaced out from one another when moving?

0 favourites
  • 8 posts
From the Asset Store
Footsteps SFX One contains 400 sounds of steps and jumps on different surfaces.
  • I have sprites following a player (followers), but when they follow, they at some point all merge together when moving. This is obviously because they're all going to the same place but I would like them to spread out a bit at all times when following player. A bit like a formation.

    At the minute the only variables differentiating them are the pathfinder speeds. top speed, acceleration and deceleration. This of course is NOT what I'm after.

    Is there a way to keep them apart from one another? Even when stopped?

    Visual of problem (GIF): ibb.co/N3QM4rF

    Here's what I'm after (image): ibb.co/1b0QZGY

  • An easy way to workaround this problem would be to have your followers go to slightly different positions. When you create them, give them an offset and apply that offset when they need to calculate their destination.

    It's not super bright, but it should work pretty well.

  • The solution may be different depending on your game. If your map has mostly open spaces with few obstacles, Diego's method should work quite well.

    But if there are lots of obstacles and tight passages, then Pathfinding objects will still overlap badly. You can add some events to slow each instance down if there is another instance in front of it. But this will also be only a partial workaround.

  • I understand where you both are coming from. The instances overlapping when they actually need to is not a problem, even it it does happen often. Its only when there's plenty of room around them and they don't all use it.

    I've added events where instances slow themselves down when another instance is within 100 pixels for example . It hasn't resulted in anything since they all remain slow moving after the event triggers.

    For Diego's method, all my instances (when in LOS) are path-finding to 'Player.X,Player.Y'. But my player's X and Y image point is the ONLY image-point on the Player and it's positioned dead centre. So they're all going to the same position (the central image point). Hence probably the overlapping and walking in a line instead of being spread out.

    I've had a go with giving them each offsets (Event sheet image: ibb.co/pLK2n7L ) but I'm uncertain what needs to be done for "they need to calculate their destination". They all have find player'sX&Y in pathfinder.

  • The way I was thinking about implementing it was like this:

    1. Add a couple of instance variables to your follower object, call them offsetX and offsetY, or something to that effect
    2. Spawn follower
    3. Assing offsetX of the spawned follower as a value relative to the target position Ex. -10
    4. Assing offsetY of the spawned follower as a value relative to the target position Ex. -10
    5. When you do find player X & Y, add the offsets of the instance to those coordinates

    Everything will still be working the same, but instead of having the followers go directly to the player, they will go to a position with a slight offset.

    Make sure that each follower has different offsetX and offsetY values, otherwise all of them will go to the same place.

  • Each of the 4 follow objects have different initial number values in the offset X and Y variables.

    -10, -20, 10, 20

    But (3) "Assing offsetX of the spawned follower as a value relative to the target position Ex. -10"

    What event should I use for adding offsets X & Y as a value relative to the target position?

    And for (5) "add the offsets of the instance to the coordinates" of player.X,player.Y , how would I add the offsets variables to the coordinates? What would the code look like?

    Event sheet: ibb.co/0MTWkT5

  • There are a few things to explain here.

    First, if your follower objects already have offsets assigned to them in the editor you can skip steps 3 and 4. Those where in case you wanted to give them a random offset at runtime.

    Keep in mind that for 4 objects you are going to need 4 sets of coordinates that will make up for a total of 8 values. To clarify:

    Follower 1
    Has offsetX instance variable and offsetY instance variable.
    Follower 2
    Has offsetX instance variable and offsetY instance variable.
    Follower 3
    Has offsetX instance variable and offsetY instance variable.
    Follower 4
    Has offsetX instance variable and offsetY instance variable.

    What I mean by relative to the target is that the offsets are values that you add to each coordinate of the target to obtain a result. This table has a few examples using actual numbers to show what I mean.

    Follower Offset (X;Y) Target Position (X;Y) Target Position + Follower Offset (X;Y)
    0 ; 0 100 ; 100 100 + 0 ; 100 + 0
    20 ; 10 200 ; 200 100 + 20 ; 200 + 10
    -10 ; -10 100 ; -100 100 + (-10) ; -100 + (-10)

    "add the offsets of the instance" means exactly that. At one point in your event sheet you must be using the Find path action of the Path behaviour and you are using the coordinates of your player object. Instead of just using the coordinates of the player object, add the offset values as well. Here is another table to try to explain this better.

    Target Position (X;Y) Target Position with offset (X;Y)
    player.X ; player.Y player.X + follower_object.offsetX ; player.Y + follower_object.offsetY

    What should happen is that, let's say your player object has a position of X = 200 and Y = 300 and a follower has offsetX = 10 and offsetY = 20, the values that you end up sending to the Find path action would be 200 + 10 for the X coordinate and 300 + 20 for the Y coordinate.

    Hope that helps.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Works brilliantly! Thank you

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