Hello! I’m currently making enemy AI for my game and I’m trying to make it so the NPC always faces the player it is chasing. Setting HRP CFrame to look at player kinda works but it makes it look like the NPC is teleporting. So the only other way I could think of is changing the C0.
Though my attempts at that result in this happening
Setting CFrame would just stop character from moving so I edit C0. There’s a high chance I’m just using lookAt wrong. BodyC0 is the default value of RootJoint.C0
It works rotating the character but it also makes them jitter and barely move. I think I should also mention that the rotation function is connected to a Heartbeat event.
I’m running this in a serverscript. And wouldn’t while loop cause the same issue? From what I understand the jittering and slow movement stems form the CFrame getting updated too fast
I’ve tried updating CFrame after the NPC reached a waypoint but that made it look like it’s teleporting instead
local function FollowPlayer(Player)
Path:ComputeAsync(Character.PrimaryPart.Position, Player.PrimaryPart.Position)
if Path.Status == Enum.PathStatus.Success then
Waypoints = Path:GetWaypoints()
local TargetWaypoint = math.clamp(#Waypoints,0,3)
if TargetWaypoint <= 1 then return end
if not Player or Player.Humanoid.Health <= 0 then return end
if Waypoints[TargetWaypoint].Action == Enum.PathWaypointAction.Jump then
TargetWaypoint = math.clamp(TargetWaypoint+2,1,#Waypoints)
Hum.Jump = true
Hum:MoveTo(Waypoints[TargetWaypoint].Position)
else
Hum:MoveTo(Waypoints[TargetWaypoint].Position)
end
local Reached = false
local Break = false
BlockedConnection = Path.Blocked:Connect(function()
BlockedConnection:Disconnect()
Break = true
return
end)
ReachedConnection = Hum.MoveToFinished:Connect(function()
ReachedConnection:Disconnect()
Reached = true
end)
task.delay(.2,function()
if not Reached and not Break then
Break = true
end
end)
repeat task.wait() until Reached or Break
end
end
And this code is connected to a while true do loop
seems to me that you’re using pathfinding
about that, i did find a post, but again i might be wrong bout this, anyway here is the post: Pathfinding NPC stuttering
its basically talking about a npc stuttering/jittering
edit: after more researching, it might be a network issue, just make sure u set the network in the code
The pathfinding isn’t what’s causing the jittering, it’s the code you suggested to make the NPC rotate towards the player, as it sets CFrame too fast not letting the character move. That’s why I was asking for help with setting C0 of the RootJoint instead of CFrame
Autorotate causes the NPC to face the direction it’s moving, not the player. Plus I want to make it so the NPC looks at the player even if they are out of reach