Pathfinding flying (triple jumping)?
So yeah i was following path finding tutorials and messing around and well my npc decided to fly / triple jump did i write my code wrong or is it just roblox glitching / i placed walls wrong.
GIF
There are 2 invis walls on each side no others
Code:
01 | local PathfindingService = game:GetService( "PathfindingService" ) |
03 | local plr = script.Parent |
04 | local humanoid = plr.Humanoid |
05 | local destination = game.Workspace.End |
07 | local path = PathfindingService:CreatePath() |
10 | local currentWaypointIndex = 0 |
12 | local function showwaypoints() |
13 | local max = #waypoints |
14 | for i, v in ipairs (waypoints) do |
17 | local part = Instance.new( "Part" ) |
19 | part.Material = "Neon" |
20 | part.Name = tostring (i) |
21 | part.Size = Vector 3. new( 0.6 , 0.6 , 0.6 ) |
22 | part.Parent = game.Workspace.WayPoints |
23 | part.Position = v.Position + Vector 3. new( 0 , 3.5 , 0 ) |
25 | part.CanCollide = false |
27 | part.BrickColor = BrickColor.new( "Lime green" ) |
29 | part.BrickColor = BrickColor.new( "Really red" ) |
34 | local function followPath(destinationObject) |
36 | path:ComputeAsync(plr.HumanoidRootPart.Position, destinationObject.Position) |
39 | if path.Status = = Enum.PathStatus.Success then |
40 | waypoints = path:GetWaypoints() |
42 | currentWaypointIndex = 1 |
43 | humanoid:MoveTo(waypoints [ currentWaypointIndex ] .Position) |
45 | if waypoints [ currentWaypointIndex ] .Action = = Enum.PathWaypointAction.Jump then |
46 | humanoid:ChangeState(Enum.HumanoidStateType.Jumping) |
49 | humanoid:MoveTo(plr.HumanoidRootPart.Position) |
53 | local function onWaypointReached(reached) |
55 | if reached and currentWaypointIndex < #waypoints then |
56 | currentWaypointIndex = currentWaypointIndex + 1 |
57 | humanoid:MoveTo(waypoints [ currentWaypointIndex ] .Position) |
58 | if waypoints [ currentWaypointIndex ] .Action = = Enum.PathWaypointAction.Jump then |
59 | humanoid:ChangeState(Enum.HumanoidStateType.Jumping) |
64 | local function onPathBlocked(blockedWaypointIndex) |
65 | if blockedWaypointIndex > currentWaypointIndex then |
68 | followPath(destination) |
74 | path.Blocked:Connect(onPathBlocked) |
76 | humanoid.MoveToFinished:Connect(onWaypointReached) |
78 | followPath(destination) |
also if you've got any script improvements / anyways to fix it please comment / reply!