# How to make the bot find a better path to the player

Hello, I have a bot that moves in 4 directions, in pathfinding when the player is in such a position and the bot in such a position it moves as it is in the image

But I wanted it to move like it is in the picture Below

Could someone help me?

I can think of 2 ways.

You can position hidden objects with the pathfinding obstacle behavior that blocks the enemyâ€™s path.

I tried doing this manually with draggable objects and it was very unstable. There might be a formula. I donâ€™t know. This seemed very sensitive and unpredictable.

Another approach would be to move the enemy in 3 steps or modes. Half the distance Y direction , align in the X and then move in the Y to the player.

1. Move from enemy.X(), enemy.Y()
to enemy.X(), (enemy.Y() + Player.Y())* .5

2. Move to player.X(), (enemy.Y() + Player.Y())* .5

3. Move to player.X(), player.Y()

If the player didnâ€™t move, the timing would be easy but since the player most likely moves, doing this dynamically would be a little tougher.

IDK the best approach for deciding when to switch modes. It would depend on how the player moves and how fast.

I wouldnâ€™t use exact numbers. Maybe switch modes by checking a range or a distance or if itâ€™s greater or less than a number based on direction.

1 Like

Hi Games, I had a play with this and came with up some ideas. It works okay but if the player and the bot were in a straight line to each other then the bot would take unnecessary detours with my method (actually itâ€™s not too bad if the obstacle is only about 20 pixels high or whatever is a narrow size for your game resolution).

I set the path for the bot to the player. Then once a path had been found, changed the bot speed to zero and positioned the obstacle in its path using the bot move pathfinding angle. Then waited a moment and then changed the bot speed back up high and set its path again. The two gifs show the obstacle hidden and not hidden.

2 Likes