#I wanna make it so i can ride a pig and you control it and it has an animation can anyone help?
1 messages · Page 1 of 1 (latest)
@quartz sonnet
local seat = script.Parent
local pig = seat.Parent
local root = pig:FindFirstChild("HumanoidRootPart")
local vel = root:FindFirstChild("LinearVelocity")
local gyro = root:FindFirstChild("AlignOrientation")
local anim = pig:FindFirstChild("Animation")
local hum = pig:FindFirstChildOfClass("Humanoid")
local animTrack = nil
if anim and hum then
animTrack = hum:LoadAnimation(anim)
end
local speed = 25
local turnSpeed = 5
game:GetService("RunService").Heartbeat:Connect(function()
local move = seat.Steer
local throttle = seat.Throttle
if throttle ~= 0 then
vel.LinearVelocity = root.CFrame.LookVector * (throttle * speed)
if animTrack and not animTrack.IsPlaying then
animTrack:Play()
end
else
vel.LinearVelocity = Vector3.new(0, 0, 0)
if animTrack then
animTrack:Stop()
end
end
root.CFrame = root.CFrame * CFrame.Angles(0, math.rad(-move * turnSpeed), 0)
end)
Place a VehicleSeat on top of your Pig model.
Inside the Pig's HumanoidRootPart, add a LinearVelocity and an AlignOrientation.
Set the Attachment0 for both to an attachment inside the HumanoidRootPart.
Set MaxForce (or MaxAxesForce) to a high number so the pig can move your character.
place the local script inside the vehicle seat
i wanna make it so when you sit on top of it and press wasd it moves the pig and the pig has the animation