Why is my npc just running into a wall even when he generates a path?
Asked by
5 years ago Edited 5 years ago
This may be a big ask but can some one look at this code and tell me why the npc is just walking into the wall even tho he generates the path and I tell him to move along the waypoints.
02 | local PathFinding = game:GetService( "PathfindingService" ) |
03 | local RunService = game:GetService( "RunService" ) |
05 | local info = script.Parent |
06 | local owner = info:WaitForChild( "Owner" ).Value |
07 | local character = script.Parent.Parent.Parent |
08 | local charRoot = character.HumanoidRootPart |
09 | local followRoot = script.Parent.Parent:WaitForChild( "HumanoidRootPart" ) |
10 | local followHumanoid = script.Parent.Parent:WaitForChild( "Humanoid" ) |
12 | followRoot.CFrame = charRoot.CFrame + charRoot.CFrame.LookVector * - 2 |
15 | local ray = Ray.new(followRoot.Position, (charRoot.Position - followRoot.Position).Unit * 360 ) |
16 | local hit,position = workspace:FindPartOnRayWithIgnoreList(ray, { script.Parent.Parent } ) |
18 | if math.abs(hit.Position.Y - followRoot.Position.Y) < 5 and math.abs(hit.Position.Y - followRoot.Position.Y) < 3 then |
19 | print ( "I can see the followRoot" ) |
26 | function createPart(positon) |
27 | local part = Instance.new( "Part" ) |
28 | part.Parent = game.Workspace |
29 | part.Size = Vector 3. new( 1 , 1 , 1 ) |
32 | part.CanCollide = false |
33 | part.Position = positon |
34 | part.Material = "Neon" |
35 | game:GetService( "Debris" ):AddItem(part, 5 ) |
38 | function moveToWaypoints(path) |
39 | local waypoints = path:GetWaypoints() |
40 | for _,waypoint in pairs (waypoints) do |
41 | print ( "Next Waypoint" ) |
42 | createPart(waypoint.Position) |
43 | if waypoint.Action = = Enum.PathWaypointAction.Jump then |
44 | followHumanoid.Jump = true |
46 | followHumanoid:MoveTo(waypoint.Position) |
51 | function generatePath() |
53 | local path = PathFinding:CreatePath() |
54 | path:ComputeAsync(followRoot.Position,charRoot.Position) |
55 | if path.Status = = Enum.PathStatus.Success then |
62 | followHumanoid:MoveTo(charRoot.Position) |
63 | RunService.Stepped:Wait( 0.1 ) |
64 | until not checkSight() |
65 | local path = generatePath() |
71 | while RunService.Stepped:Wait( 0.1 ) do |
https://gyazo.com/a47aa6ddcd5f31100fae150f808e9469