Hey,
Recently I’ve been practicing my scripting with a tower defense game, and I found that the NPC’s are walking into a wall instead of going through the corners. Example:
How could I fix this? Should I not use
:MoveTo()
?
Hey,
Recently I’ve been practicing my scripting with a tower defense game, and I found that the NPC’s are walking into a wall instead of going through the corners. Example:
:MoveTo()
?
could we see the script to see it clearer?
I don’t presume Humanoid:MoveTo() is eligible to correctly sustain a pathway - therefore, only reaching towards the position without measuring turns. You’d need to use PathfindingService instead.
PathfindingService is used to find paths between two points. These paths make sure that characters can move between the points without running into walls or other obstacles. Paths can be used for both player-controlled characters and non-player characters.
Your NPC’s are running into a wall because Humanoid:MoveTo() tries to make the Roblox Character walk a direct path to the Position it wants to go to.
Obviously,MoveTo() does not check for obstacles.
What you need to use is a service called Path Finding Service. The Roblox Dev Hub has a great page on it:
@Doqee already said this, but thanks
Path finding is incredibly intensive, and will get very laggy when there are a lot of NPCs.
It is best in this case to have a set of points the NPC will walk to.