A good working npc pathfinding system

I want to make a npc that can pathfind well that chases you upon detection, but my current version is too awkward.
Here’s my code



image

What my npc currently does isn’t something that works or looks smooth at all.

As you can see I can run circles around him, he also stops occasionally. I want him to be able to track and follow me while continuously moving.

Thanks in advance anyone who bothers to help.

replace wait(.1) to wait(). maybe the solution

A simple solution is to do a raycast and check if the target is in a direct line of sight.

If the player can be reached in a straight line then there is no reason to use pathfinding as it tends to be pretty slow at chasing.

You usually use pathfinding for making NPCs get around walls or walk upstairs to a different floor.

Could you provide a example, I want to just get past this thing, because I’ve been stuck on this for a while.
It’ll be helpful if you do.

When the player turn, the npc try to find it in his vision but fails.
Can you add angle to the raycast?