(I don’t know if that video will appear as a preview, sorry if not)
So far I’ve tried using a BodyGyro to add smooth turning, but it more just makes it look like delayed turning, as it walks in 1 direction, and slowly turns towards the direction.
I have also tried Pathfinding, but this either comes out as super laggy and gittery, or doesn’t turn smoothly
Code currently:
local function actuallyMoveTheNPC(npc, waypoints, waypoint, Humanoid, BodyGyro)
local waypoint = waypoints[waypoint]
local path = PathfindingService:CreatePath({
AgentRadius = 2,
AgentHeight = 5,
AgentCanJump = false,
AgentCanClimb = true,
WaypointSpacing = 1
})
path:ComputeAsync(npc.HumanoidRootPart.Position, waypoint.Position)
local AssemblyMass = npc.HumanoidRootPart.AssemblyMass*400
BodyGyro.MaxTorque = Vector3.new(AssemblyMass, AssemblyMass, AssemblyMass)
for index, waypoint in path:GetWaypoints() do
-- Move
BodyGyro.CFrame = CFrame.new(npc.HumanoidRootPart.Position, Vector3.new(waypoint.Position.X, npc.HumanoidRootPart.Position.Y, waypoint.Position.Z))
repeat Humanoid:MoveTo(waypoint.Position)
local reached = Humanoid.MoveToFinished:Wait()
until reached
end
end
Try tweenservice because it’s easy and efficient, however may not be 100% to your liking. Depending on the what it’s tweening. Try it out and see how you feel about it, if you don’t like it I’ll help you figure out another way!
What to do: find the part to rotate. If it’s a NPC I’m gonna assume it has a HumanoidRootPart, simply tween the CFrame’s angle by the degree the NPC is turning to.
Consider using AlignOrientation rather than BodyGyro. You can then increase the responsiveness to make the NPC rotate more quickly. There’s also the property RigidityEnabled that would make the NPC turn as quickly as possible towards the specified CFrame.
I basically need an NPC to move to waypoints using PathfindingService. However instead of it going into the waypoint, snapping, then walking again, I want it to slowly turn as it approaches the waypoint, so it looks more life-like.
I use AlignOrientations for these. All my NPCs have an invisible ‘Looker’ part that’s used as the dominant attachment of the AlignOrientation. When the NPC needs to update where its looking, the invisible part is changed to face the target direction, with the AO following shortly after. This also helps the NPC keep facing a direction if they’re pushed around by things like LinearVelocities.
You can also change the responsiveness to set how quickly the NPC turns to face the direction.
For anyone coming back to this post in the future, SimpleSpline works insanely well. If you combine this with AlignOrientation, and a separate part, you can get some really nice results.