#help in studio model wont move pathfinding
1 messages · Page 1 of 1 (latest)
accident, sending my issue
my model wont move, Ive tried many variations of pathfinding code to make it move from one space to another, it does not work. It is not a normal model, has no humanoid but the Main part is a normal part. Im not sure how to make this work
"apt" is the PrimaryPart
do you know how to solve it
local PathfindingService = game:GetService("PathfindingService")
local model = workspace.MyCustomModel -- replace with your model
local destination = workspace.Target.Position -- some part to path to
local function moveModel(model, destination)
local humanoid = model:FindFirstChildWhichIsA("Humanoid")
if not humanoid then
-- Add a temporary humanoid for movement
humanoid = Instance.new("Humanoid")
humanoid.Parent = model
end
local path = PathfindingService:CreatePath({
AgentRadius = 2,
AgentHeight = 5,
AgentCanJump = true,
AgentJumpHeight = 10,
AgentMaxSlope = 45,
})
path:ComputeAsync(model.PrimaryPart.Position, destination)
if path.Status == Enum.PathStatus.Complete then
local waypoints = path:GetWaypoints()
for _, waypoint in ipairs(waypoints) do
model:MoveTo(waypoint.Position)
model.MoveToFinished:Wait()
-- Optional: handle jumps
if waypoint.Action == Enum.PathWaypointAction.Jump then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
end
else
warn("Path not found!")
end
end
moveModel(model, destination)
what is that?