Making a Wagon With Spinning Wheels Which Follows the Player

I am trying to create a wagon which will have spinning wheels.

I’ve already welded it to the player, but the problem is that I cannot figure out how to get the wheels to spin.

I’ve tried using AngularVelocity and HingeConstraints, but neither have worked. The wagon is all CanCollide = false because It would sping up from the ground when not. This is likely why these solutions have not worked.

I know that you can do something like

RunService.RenderStepped:Connect(function()
     task.wait()
     Wheel.CFrame = Wheel.CFrame * CFrame.Angles(0, 0, 1)
end)

However, this would be less smooth and stopping the wheels would be harder to implement.

I could also change the speed of the rotation to 0 when the player stops moving but I would love to know if there are any better ways to accomplish this.

Here is a video of the current wagon for reference (the wheels would need to stop spinning when the player stops moving.)

Hi! You can do this with Motor6D. Here’s script for example:

local Runservice = game:GetService("RunService")
local Players = game:GetService("Players")
local Character = Players.LocalPlayer.Character
local Humanoid = Character:WaitForChild("Humanoid")

local Wagon = Instance.new("Part") --Creating Wagon
Wagon.Name = "Wagon"
Wagon.Position = Vector3.new(0,10,0)
Wagon.Size = Vector3.new(5,5,10)
Wagon.Parent = workspace

local Wheel = Instance.new("Part") --Creating Wheel
Wheel.Name = "Wheel"
Wheel.Size = Vector3.new(1,3,3)
Wheel.Color = Color3.fromRGB(255,0,0)
Wheel.Parent = Wagon

local Joint = Instance.new("Motor6D")
Joint.C0 = CFrame.new(3,0,3) --WheelOffset
Joint.Part0 = Wagon
Joint.Part1 = Wheel
Joint.Parent = Wagon

Runservice.RenderStepped:Connect(function() --Getting moving of character and rotating wheel
	Joint.C1 = Joint.C1 * CFrame.Angles(math.rad(Humanoid.MoveDirection.Magnitude),0,0)
end)

Put code in ServerScript and check

Thanks, I managed to get this working using the RenderStepped MoveDirection loop.

I was also able to change the wheel movement based on the players speed with

local wheelspeed = Humanoid.MoveDirection.Magnitude * Humanoid.WalkSpeed / 10
Joint1.C1 = Joint1.C1 * CFrame.Angles(0, 0, math.rad(Humanoid.MoveDirection.Magnitude))
Joint2.C1 = Joint2.C1 * CFrame.Angles(0, 0, math.rad(Humanoid.MoveDirection.Magnitude))

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.