Pathfiding drops a lot frames for an enemy Flying

I’ve making an Enemy flying chases the player with pathfiding but if i’m far from enemy it will drop fps too much like 10 fps

but if i use force it won’t drop fps but dosen’t do smooth movement

i wanna make a smooth movement for an ememy flying and chases player
is there a solution that it won’t drop fps on pathfiding?

[If an enemy is far from the player it will change the speed to reach a player, if is closer to a player it will slow down]

Hey there,

The pathfinding does a lot of calculations to determine the shortest path the object should move on and avoid obstacles. Especially for a long distance, the calculations take more time to find the path.

So it’s more resources heavy than using a force that only pushes the enemy towards the player in a straight line.

Try setting a timer to call the action Move enemy to player every like 0.25-1 seconds, instead of calling it on every frame.

Also can you explain more what you mean by smooth movement? And do you have obstacles the enemy should avoid while following the player?

a smooth movement i mean that how much speed between closer (low speed) or far (high speed) from the player there’s no obstacles it’s like a ghost chases to the player and ty i will try using a timer

I found out i can use a Tween to follow player smoothly instead pathfiding and Insein thx but still drops frames lil bit and works well with Tween

The tween can produce bugs and is not a good solution for this mechanic. You also don’t need pathfinding.

What you can do is use a force and set the speed to the variable speed and change it smoothly.

Try this:

  • (inv) Boss distance is below 800 → Change variable speed to: clamp(speed+1, 180, 320)
  • Boss distance is below 800 → Change variable speed to: clamp(speed-1, 180, 320)
  • [no condition] → Move boss toward Player with an instant force of: speed

You can add or subtract a higher / lower number to make the speed transition faster or slower. Eg: speed+2 or speed+0.5

It works thank you i use force for now on

You’ve got an unconditional pathfinding Move statement in your first screen shot. Pathfinding uses a fair bit of processing time, so to do that every single frame will take it’s toll.

Instead you could use a timer to reduce the number of Move actions being performed, from every game frame (~60 times a second) to a few times per second by using 0.5 or 0.25 as the timer limits.

Why did my post from almost 1.5 days ago only just pop up now?

Ty i tried but still bit takes frames but i use force for now on