Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

A* Pathfinding algorithm seems to not work for bigger torso?

Asked by 3 years ago

i am trying to make an pathfinding npc but this is what i see if i put a normal sized torso it avoids walls but when i make the torso a bit bigger it seems to not avoid the wall

My code for roblox pathfinding:

local pathfindingService = game:GetService("PathfindingService")
local humanoid = script.Parent.Humanoid
local body = script.Parent:FindFirstChild("HumanoidRootPart") or script.Parent:FindFirstChild("Torso")
local destination = game.Workspace.Destination.Position
local path = pathfindingService:CreatePath()
path:ComputeAsync(body.Position, destination)
local waypoints = path:GetWaypoints()
for k, waypoint in pairs(waypoints) do
    humanoid:MoveTo(waypoint.Position)
    if waypoint.Action == Enum.PathWaypointAction.Jump then
        humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
    end
    humanoid.MoveToFinished:Wait()
end
0
you are calculating based on the bodies position, not the size. Roblox's path finding service usually accounts for this I recommend using that. If you want to full account for size then use raycasting. You can also disable collisions for the wall and let the body move through it. DollorLua 235 — 3y

1 answer

Log in to vote
1
Answered by
QWJKZXF 88
3 years ago

The reason your pathfinding script is not working with a bigger torso is that Roblox's pathfinding service defaults for a normal character, which is 5 studs tall, about 3 studs in width. What you need to do is to add in path parameters.

local pathfindingService = game:GetService("PathfindingService")
local humanoid = script.Parent.Humanoid
local body = script.Parent:FindFirstChild("HumanoidRootPart") or script.Parent:FindFirstChild("Torso")
local destination = game.Workspace.Destination.Position


local pathParams = {
    ["AgentHeight"] = 5, --The height of the character
    ["AgentRadius"] = 2, --The width of the character from end of left arm to right arm times half.
    ["AgentCanJump"] = true --Can the character jump?
}

local path = game:GetService("PathfindingService"):CreatePath(pathParams)

path:ComputeAsync(body.Position, destination)
local waypoints = path:GetWaypoints()
for k, waypoint in pairs(waypoints) do
    humanoid:MoveTo(waypoint.Position)
    if waypoint.Action == Enum.PathWaypointAction.Jump then
        humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
    end
    humanoid.MoveToFinished:Wait()
end

In the path params, you would need to adjust the values according to the size of your character.

0
Thankyou @QWJKZXF Retallack445 75 — 3y
Ad

Answer this question