wait(5)
local rig = script.Parent
local animationController = rig:FindFirstChildOfClass("AnimationController")
local humanoid = rig:FindFirstChildOfClass("Humanoid")
function RunAnimation(animation, speed, priority, fadeIn)
local animTrack = animationController.Animator:LoadAnimation(animationController.Animations[animation])
animTrack:Play(fadeIn, priority, speed)
return animTrack
end
function StopAnimation(animationName)
for _, track in pairs(animationController.Animator:GetPlayingAnimationTracks()) do
local animName = track.Animation.Name
if animName == animationName then
track:Stop()
end
end
end
local walkspeed = 16
local pointToWalkTo = Vector3.new(-6.218, 0, -101.885)
local path = game:GetService("PathfindingService"):CreatePath({
AgentRadius = humanoid.HipHeight / 2,
AgentHeight = humanoid.HipHeight,
AgentCanJump = true,
AgentJumpHeight = 10,
AgentMaxSlope = 78,
})
path:ComputeAsync(humanoid.Parent.PrimaryPart.Position, pointToWalkTo)
if path.Status == Enum.PathStatus.Success or path.Status == Enum.PathStatus.ClosestNoPath or path.Status == Enum.PathStatus.ClosestOutOfRange then
local waypoints = path:GetWaypoints()
local animTrack = RunAnimation("Run", walkspeed / 16, 3, 0.4)
for _, waypoint in ipairs(waypoints) do
local startPosition = humanoid.Parent.PrimaryPart.Position
local targetPosition = waypoint.Position
local distance = (targetPosition - startPosition).magnitude
local timeToTravel = distance / walkspeed
local startTime = tick()
local initialLookVector = humanoid.Parent.PrimaryPart.CFrame.lookVector
local targetLookVector = (targetPosition - startPosition).unit
while true do
local elapsedTime = tick() - startTime
local lerpedPosition = startPosition:Lerp(targetPosition, elapsedTime / timeToTravel)
local lerpedLookVector = initialLookVector:Lerp(targetLookVector, elapsedTime / timeToTravel)
humanoid.Parent:SetPrimaryPartCFrame(CFrame.new(lerpedPosition, lerpedPosition + lerpedLookVector))
if elapsedTime >= timeToTravel then
break
end
wait(0.01)
end
end
humanoid:MoveTo(humanoid.Parent.PrimaryPart.Position)
StopAnimation("Run")
else
print("Pathfinding failed:", path.Status)
end
This script is made to achieve the process of moving a Dog model smoothly to it’s desired position. However it has some issues.
- Animations not playing
- Dog model walks into the ground and moves to the target from the ground, HipHeight isnt doing anything in the humanoid or the script’s PathAgentRadius/PathAgentHeight
Any Questions, Comments, Solutions, and tips are greatly appreciated.