Hello, at the moment my pathfinding NPCs appear to be really jolty and i don't believe it is to do with server lag because when i fire my gun the projectile is moving at a good speed. So i believe it is to do with the path the NPCs are following. Anyone know how i would fix this?
local head = script.Parent.Parent:FindFirstChild("Head") while true do local PathfindingService = game:GetService("PathfindingService") local NPC = script.Parent.Parent local Humanoid = NPC.Humanoid local RootPart = NPC.HumanoidRootPart local Target = workspace.NoirPhoenix:FindFirstChild("HumanoidRootPart") local Start = RootPart.Position local Goal = Vector3.new(Target.Position.X -7,Target.Position.Y, Target.Position.Z) local path = PathfindingService:FindPathAsync(Start, Goal) local waypoints = path:GetWaypoints() for waypointIndex, waypoint in pairs(waypoints) do local waypointPosition = waypoint.Position if waypointPosition.Y >= head.Position.Y then print("Jump") Humanoid.Jump = true end Humanoid:MoveTo(waypointPosition) Humanoid.MoveToFinished:Wait() end wait() end
Here. what you can do is use this line before " local path = PathfindingService:FindPathAsync(Start, Goal)"
local frame = (RootPart.CFrame*CFrame.new(0,0,-5)).Position Humanoid:MoveTo(frame)
This basically moves the npc forward until it calculates a path over to the player, stopping the noticeable gaps between the use of pathfinding. ALSO, something I noticed that was a widespread problem with Humanoid:Moveto() is that there is a pausing problem between each step of a waypoint. to fix this, simply put the following code in the beginning of the script after the variables are created:
NPC.PrimaryPart:SetNetworkOwner(nil)
This prevents the network ownership from being tossed from player to player and instead relies on the server for physics functionality, stopping the velocity from decreasing and increasing and making the movement 100% more smoother.
your welcome :D
The path usually isn't the issue for jittery movement with the Pathfinding Service. It (probably) is giving a regular set of points that would allow you to get from start to finish smoothly. If you don't think this is the case - try looping through the points given in your path, and create a new Part
instance to indicate each point your AI is moving through.
More often than not, it is the technique you use to move your AI. If you are setting the AI's CFrame to the next point and just Wait()
ing, then you would have jittery movement - as opposed to using the :MoveTo()
method from Humanoid
.
There are many options for smooth movement:
RenderStepped
functionI hope this helps.