Hello developers 
Insight
I am creating an AI system like “The Mimic”.
Details
I wanted to create my own pathfinding system for the AI, whose behavior is as follows.
- When the player is in sight, The AI uses
:MoveTo() instead of pathfinding. (For smooth pathfinding)
- When player is out of sight (like entered a safe zone etc), the AI goes to the last seen position of the player and then pathfinds to the player’s character.
Media (sorry about lag in the beginning)
Information About Media Provided
When the player is in sight of the AI, a custom indicator named “CHASE” is placed at the feet of the player, indicating that the player is in sight and that it’s being chased.
When the player is out of sight, the chase indicator stops at the “Last Seen Position” of the player it was chasing and then pathfinds to the player’s HumanoidRootPart if the player is not in the safezone, creating a seamless transition.
If the player is safe, it pathfinds to the safezone entrance and then goes back to patrolling (indicated by the screen zooming in).
Phew, that was a lot… you can take a deep breath now!
Thank you
4 Likes
I think there’s something wrong with the video. All I see are just pixels lagging incredibly badly.
1 Like
Excuse me for the video, I’ll re-record it again 
Stupid recorder, I should’ve checked it once
1 Like
I added the video back to the message, sorry about the inconvenience though 
1 Like
And, what problem do you have? The NPC in the video looks just fine
1 Like
The NPC in the video uses a Roblox module called AIEngine by Sythivo, the programmer of The Mimic.
I wanted to recreate this type of system in my own version of the AI.
I hope it clears some things up 
(It was implemented by Sythivo himself for the Examples)
1 Like
Oh, so the video shows how you want it to be?
What did you get done so far?
I would get the following functions done:
- a function to pathfind and walk to a position
- a function to find the player’s last position before entering a safezone
- a function to check if the player is inside a safezone
Here is a simple explanation how you can do each function:
3. to check if the player is in the safezone you can check if the character’s PrimaryPart is inside a Region. This function can be a example:
local function isPlayerInSafezone(player, safezonePart)
local character = player.Character
if not character then
return false
end
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if not humanoidRootPart then
return false
end
local region = safezonePart.Size * CFrame.new(safezonePart.Position)
return region:ContainsPoint(humanoidRootPart.Position)
end
- Capture the player’s position every frame, and if the player isn’t inside a safezone then change some variable or element in a table
- Use classic pathfinding to get the points, and move the NPC to each point
The AI is completed.
Chasing, Patrolling, Safezones etc etc.
Instead of pathfinding to the player when it’s in the AI’s vision, why not make it so that it uses only :MoveTo() assuming that there are no obstacles in the way of the AI? And when the AI has lost the player, pathfind to the player’s root position if the player is not safe.
But I can’t really think of a way I could do that.
Maybe the only way for me to do that would be reverse engineering the module to see how it really works.
You cannot think of a way to do what? To check if there are no obstacles between the NPC and the player? If so, just use simple raycasting
I meant the whole “:MoveTo() if the player is in vision, else pathfind to the player” thing.
If the raycast returns a part of the player run MoveTo to the player’s PrimaryPart position else use pathfinding to move to the last player position?