Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make an AI which moves to the player?

The pathfinding service is good for moving to a stationary target, however I have struggled to use it to make an AI mob which moves to a moving target (the player). I did try using a mixture of raycasting and pathfinding, but trying to constantly update the pathfinding always creates a really buggy output. Could anyone help?

2 comments

0

Have you tried using Humanoid:MoveTo to move the NPCs to the player's position? https://developer.roblox.com/en-us/api-reference/function/Humanoid/MoveTo

0

Yeah I already about that, thats what I use to move to the node positions on the GetWaypoint function of pathfinding. If I simply do a loop of moving to the players position the Ai will simply walk in a straight line and not avoid any terrain in the way

1 answer

If the AI is made with a humanoid object, you can use humanoid:MoveTo(position, target). It takes in the target's position and the target in order to change direction if the target moves. I'm pretty sure that the function doesn't stop until it reaches the target location. You can read more about it here - https://developer.roblox.com/en-us/api-reference/function/Humanoid/MoveTo.

1 comment

0

Yeah I already about that, thats what I use to move to the node positions on the GetWaypoint function of pathfinding. If I simply do a loop of moving to the players position the Ai will simply walk in a straight line and not avoid any terrain in the way

This discussion is preserved as it was. New answers, comments, and votes are closed.