Is there anyway to adjust the distance of one waypoint to another?

Is there anyway of implementing such thing? If yes, can you give me an idea of how? If no, then I’m thinking of just skipping every other waypoints.

This is what I have and I want to tween the HumanoidRootPart to kind of like hop to the next waypoint.

local TweenService = game:GetService("TweenService")
local PathfindingService = game:GetService("PathfindingService")

local animateEvent = game.ReplicatedStorage.AnimateEvent

animateEvent.OnServerEvent:Connect(function(player, destination)
	local character = player.Character or player.CharacterAdded:Wait()
	local humanoid = character:FindFirstChild("Humanoid")
	local rootPart = character:FindFirstChild("HumanoidRootPart")
	
	local tween = TweenService:Create(rootPart, TweenInfo.new(0.5,Enum.EasingStyle.Sine),{Position = rootPart.Position + Vector3.new(0,2,0),Orientation = Vector3.new(45,0,0)})
	
	local path = PathfindingService:CreatePath()
		
	path:ComputeAsync(rootPart.Position,destination)
	
	local waypoints = path:GetWaypoints()
	
	for i, waypoint in ipairs(waypoints) do		
		----------[TEST]----------
		local part = Instance.new("Part")
		part.Position = waypoint.Position
		part.Anchored = true
		part.CanCollide = false
		part.Size = Vector3.new(1,1,1)
		part.Shape = Enum.PartType.Ball
		part.Material = Enum.Material.Neon
		part.Parent = workspace
		----------[TEST]----------
				
		humanoid:MoveTo(waypoint.Position)
				
		if waypoint.Action == Enum.PathWaypointAction.Jump then
			humanoid.Jump = true
		end
				
		if humanoid.WalkToPoint ~= waypoint.Position then break end
	end
	
	humanoid.MoveToFinished:Wait()
end)
1 Like

Maybe you could try doing this? (in a nutshell, i += 2 every time the loop runs, thus skipping every other number)

for i = 1, #waypoints, 2 do 
    local waypoint = waypoints[i]
    -- rest of code
end
2 Likes

If you want to adjust the distance between waypoints to a specific number, you can put in parameters of the CreatePath function with a dictionary of agent parameters.

Options of agent parameters are on the top of the page of:

You can tweak the WaypointSpacing parameter like so:

local pathParameters = {
[“WaypointSpacing”] = <specific distance you want>
}

path:CreatePath(pathParameters)

(Note: You can raise this distance to a ridiculously high number but it will still adjust to any turns or corners that the path has to stop any ‘stuck’ issues)

8 Likes

can you explain it further more i don’t quite understand what u trying to say

Sure thing. When you using PathfindingService:CreatePath(), you can pass in a table of values which determine the “agent” (the npc walking using pathfinding in this case) features. These features range from how hypothetically wide the agent is (AgentRadius) to whether or not the agent can jump (AgentCanJump).

One of the available features that Roblox allows you to plug in is the WaypointSpacing, which forces the NPC/Agent to make one waypoint every certain studs when you call the Path:GetWaypoints() function. (For example, if you put the WaypointSpacing as 5 studs, it will create a line of waypoints to the destination, each one being exactly 5 studs away from one another).

However, sometimes the path to the destination can have turns, and if the path is forced to comply with the WaypointSpacing parameter at all times, it would be impossible to consistently make a sharp, efficient turn (the forced spacing will make the agent overshoot the corner). Hence, WaypointSpacing forces the waypoints to be a certain distance from each other only when no difficulties in the path make it inefficient.

And please check out the link to the documentation if this is still unclear, they probably explains it better than I can anyway.

1 Like