Pathfinding not recalculating and passing through obstacles

I know there’s been a lot of topics about pathfinding, but I haven’t found any that would help me.

Context

I’m spawning objects that have the pathfinding behavior to move to the position of the player, and there are pathfinding obstacles on the way.

The issue

The objects detect the initial position of the player when spawned and will move there, but will not recalculate when the player moves, they reach the initial position and stop there.

Also the objects that have the Pathfinding Obstacle behavior are not blocking the movement of the spawn, they just pass through it.

I read through the wiki about Pathfinding and searched through the forum, but haven’t found what I’m doing wrong.

1 Like

A screenshot of your events would help but here’s what I’ve learned about pathfinding.

If you’re adding walls, don’t copy, paste and rotate the walls. For some reason, rotated objects can sometimes be ignored. Copy/paste and then resize. So, you have tall objects and wide but not rotated.
To move, the object needs to be able to reach a location and fit completely inside the target location or it won’t move. Sometimes a player is too close to a wall.
Setting the grid size to a lower value will get you into tight spots. If it’s too large, it might not move or it might ignore obstacles.

:laughing: You already fixed one of the issues - pathfinding objects are now avoiding obstacles. I made sure I don’t have any copies of the obstacles and increased the grid size, and that worked. Thank you!

But they are still not recalculating the path. I don’t have any walls, I just have a flat texture for the ground and a few tombstones as the obstacles for the objects.

As you can see here, they lock on the initial position of the player and ignore the new position after I move (don’t mind the assets, or anything else, everything is temporary :sweat_smile:)

What about your events? You might need to put the zombies in a for each object We need to see your events to be able to help.

Ah, sorry, I thought I posted it as well:

Are those all of the event? You need to occasionally update the path data. The move action plots a path using nodes or points and then the object follows them. It doesn’t update the path until it’s given another destination through the move action.

Depending on the number of objects and your intentions there are a few ways I’ve seen people update the path.

For, simple games, I’ve seen people update the path to the current player on every frame using the move action to without a condition. I would not recommend it. It uses a lot of resources.

You can use object timers and only update the path a few times a second. IDK the correct frequency. It would be trial and error.

You can do a mix of both. Check the distance and change the object timer frequency based IBM distance. Use a longer time has elapsed when the object is far away and a shorter time when the zombies are closer to the player.

The other method is only good for a none moving target. You would use the reached destination condition so the object follows the entire path before picking its next destination. For a moving object this would create too large if a lag.

With any method, you might need to use for each object it depends on the action(s).

Yes, those are all the events related to spawning the objects and the pathfinding.

And you’re right, as always, I took the pathfinding action out of the condition and it started working.

Do you have an example of how to use the object timer? I haven’t used it yet.
Do you use it on the object that uses the pathfinding? How would this look like?

When you create the zombie, add an object timer in the same group, leave the initial Pathfinder move to get it moving

New event
Add condition
Zombie Object timerName elapsed >= .3

Actions
Pathfinder Move zombie to players position
Reset timer

IDK the ideal amount of time. Too large and the zombie will always target the players previous position. Since the timer is started when the zombie is created the timers should mostly expire at different times. That will reduce and spread out the recalculations.

Small changes add up fast when you’re doing studs 60 times per second times the number of objects. If you build in efficient code from the start then you’ll have less to optimize later.

You might find an ideal timer amount with a simple project without a lot of moveable objects and/or obstacles.

If you check the distance, you could use 2 events

Distance between objects => 300
Object timer >= 1 second
Move zombie
Restart zombie timer

Distance between objects < 300
Object timer >=. 3 second
Move zombie
Restart zombie timer

Since each group would be targeting the same location, I don’t think you would need for each object I could be wrong.

If **for each object ** is needed, I usually put it after the shared condition. Conditions work like filters. It’s better to filter the list first and just loop through them instead of looping through every object whether it’s needed or not.

Example

Distance between objects => 300
Object timer >= 1 second
(the Subevents would be) 
   For each zombie
      Move zombie
      Restart zombie timer

Alternatively, since all objects are being moved you could use a **for each object ** with both distance conditions.

I wasn’t going to make an example but I wanted to test my idea. Something like this. It’s not completely test. So, there could be bugs.

I know you don’t delete your dead zombies. You would have to either check if the zombie is alive through the animation before the timer and move conditions or I guess you could just delete the zombie timer when they die. Although it would still be calculating the distance between player and zombie. So, you could check the animation first.

A better way might be when the zombies die, add a different object of a dead zombie in its x, y and delete the active zombie. Then you wouldn’t have to filter between living and dead zombie.

You could then control how many dead zombies are on screen. Maybe delete the dead zombies after a certain time with their own timer or an animation. They could decay or sink into the ground. That would keep the object count down. Otherwise, things might eventually start to lag.

Edit: I see you are deleting the zombies. It would still apply because you don’t want dying (for a second time) zombies to move.

I wonder if dead zombies could comeback to “life” after a certain amount of time. It’s a bit like a skeleton that turns into a pile of bones reforming after a certain amount of time. I like that concept. I need to try that.

I forgot I made a zombie project. I couldn’t find it here. So, maybe I never posted it here.

If you’re on Twitter
https://twitter.com/KeithHixDesigns/status/1647105304079790080?s=19

I must say I don’t understand for now how the object timer works :thinking:

When I add it to the pathfinding movement the zombies stop moving.

When you create the object , you need to create the timer or start/reset it to get it going.

Below the add object add the start timer. Same event.

Like this?

They’re still not moving.

Ah, you’re checking a scene timer, you need to. Check the object timer. It’s listed under the object like other conditions. (your last line)

That did it, thanks!

For the zombies 0.5 sec seems to be enough for pathfinding since they are slow themselves.

1 Like