I am experiencing a persistent issue where an enemy using the Pathfinding behavior teleports or snaps to incorrect positions (often near the player) after being pushed. Even when I deactivate the Pathfinding behavior to apply a force or use the “Separate Objects” action to move the enemy away, the object glitches as soon as the player moves or the behavior is re-enabled. It seems the Pathfinding doesn’t update its internal coordinates correctly when the object is displaced externally, causing it to “remember” an old position or conflict with the new one. This happens even if I try to make the enemy “chase” the projectile instead of using forces. The expected result is that the enemy stays at its new position after the push without snapping back.
When you use the move to action for an object with the pathfinder, it creates a path. It creates a list of x and y for nodes. It won’t update the path again until the move action is triggered again. Disabling the behavior only pauses the process.
You might be able to trigger the pathfinder move action again after the objects are pushed or seperated. That would update the path. Although, I’m not sure of how efficient that would be
Are you seperating the objects from other moving objects or from obstacles? I’m guessing you’re trying to prevent clumping or stacking of objects.
Yeah I noticed that too but I don’t know how to fix it yet Can you help me set up this trigger to update the path I’m not sure if I should use a timer or if there’s a better way to reset the movement action
If you’re seperating the objects then you could use a collision condition seperate and then do the move to the destination.
I’m at work and I don’t have much time.
Something like
collision x with z
… Seperate objects only Z moves
… Move z to its destination.
If they’re the same object then you might need a for each object as a subevent to the collision condition because it’s tough to tell which object is the one that for pushed away.
Keeping objects seperated is a difficult task. I’m surprised that GD doesn’t have more built-in solutions.
Someone recently was working on a pathfinder method that prevents objects from overlapping. I never tested it.
Even if you seperate objects, if they have the same destination. They’re liable to just clump back up.
Some strategies.
Instead of pushing an object away. Maybe you could pick a random one to slow down or stop briefly. This would allow the object to space out.
You can use both the pathfinder and the pathfinder obstacle on the same objects. I just don’t know how efficient it is.
You would have to disable the obstacle behavior one object at a time just before moving it and then re-enable it. Only the object that is just about to move would have the obstacle behavior disabled. That way the object can still plot a path around it. This isn’t my favorite idea. The objects could create a blockage or bulk up too much.
Space the objects. Say you had a troop of 10 objects that start from the same position. You can use a timer to gradually move them one at a time. I like this technique. It’s very orderly.
You can spawn them from different locations.
You can have them target different destinations around the target object. Instead of targeting the object center. You can target a position that is say 50 pixels from the center and change the angle. So, 1 object might move to a place that’s 90° in one direction and another might target a place 45° off.
Some people use the Boids behavior. That’s only really good with birds or fish or something that flocks or swarms. I personally don’t like it for anything but birds or maybe flying vehicles.
You might be able to use a hidden pathfinder object for the path and then have another object loosely follow it. I’m really not sure how this would work.
Another approach might be to use formations. You could move a group in unison.