Hello, I’m currently using pathfinding to figure out a path. My problem is that for some reason the targetposition’s Y Value defaults to 0, even though I for a fact know its not (Printing out the Y Value which returns not a 0).
My Code:
local function Pathfinding(TEST_DESTINATION, character)
local path = PathfindingService:CreatePath({
AgentRadius = 2,
AgentHeight = 10,
AgentCanJump = false,
})
local waypoints
local nextWaypointIndex = 0
local reachedConnection
local blockedConnection
local function followPath(destination)
local c = false
local success, errorMessage = pcall(function()
path:ComputeAsync(character.Position, destination)
end)
if success and path.Status == Enum.PathStatus.Success then
-- Get the path waypoints
waypoints = path:GetWaypoints()
for i,v in pairs(waypoints) do
local cc = Instance.new('Part')
cc.Anchored = true
cc.Size = Vector3.new(1,1,1)
cc.Position = v.Position
cc.Parent = workspace
cc.CanCollide = false
end
blockedConnection = path.Blocked:Connect(function(blockedWaypointIndex)
-- Check if the obstacle is further down the path
if blockedWaypointIndex >= nextWaypointIndex then
-- Stop detecting path blockage until path is re-computed
blockedConnection:Disconnect()
-- Call function to re-compute new path
followPath(destination)
c = true
end
end)
while nextWaypointIndex < #waypoints do
-- Detect if path becomes blocked
if c then
break
end
nextWaypointIndex = nextWaypointIndex + 1
character.Position = waypoints[nextWaypointIndex].Position
wait(4)
end
--humanoid:MoveTo(waypoints[nextWaypointIndex].Position)
else
warn("Path not computed!", errorMessage)
end
end
followPath(TEST_DESTINATION)
end
local function MoveEvent(Plr, Destination, Object1, Object)
local NewDestination = Vector3.new(Destination.X, Object1.Y, Destination.Z)
Pathfinding(NewDestination, Object)
end
The MoveEvent is a remoteevent that’s connected whenever the Player presses. The object is the object that is going the pathfinding is originating from.
Any help is welcome!
Edit (Video of whats happening):
Edit 2:
Even manually setting the destination in the Path:ComputeAsync() with a Y position of 5 produces the same result. The waypoints Y Position is 0