I am trying to make the wheels on a jeep rotate when the jeep turns. However, the wheels do rotate properly, but only when the jeep is still. When the jeep moves, the wheels spin weirdly. Here is a capture of the problem:
https://gyazo.com/b7ce8fc1569bf122eb9dd251e97c7e12
The part of the script responsible for making the wheels spin and rotate is here:
function spinWheels(direction)
local factor
if direction == "Forward" then
factor = 10
elseif direction == "Backward" then
factor = -10
else
factor = 0
end
local spin = coroutine.wrap(function()
while s do
wheels.BackLeftWheel.PrimaryPart.Motor6D.C0 = wheels.BackLeftWheel.PrimaryPart.Motor6D.C0 * CFrame.fromAxisAngle(Vector3.new(0, 0, 1), math.rad(factor))
wheels.BackRightWheel.PrimaryPart.Motor6D.C0 = wheels.BackRightWheel.PrimaryPart.Motor6D.C0 * CFrame.fromAxisAngle(Vector3.new(0, 0, 1), math.rad(factor))
wheels.FrontRightWheel.PrimaryPart.Motor6D.C0 = wheels.FrontRightWheel.PrimaryPart.Motor6D.C0 * CFrame.fromAxisAngle(Vector3.new(0, 0, 1), math.rad(factor))
wheels.FrontLeftWheel.PrimaryPart.Motor6D.C0 = wheels.FrontLeftWheel.PrimaryPart.Motor6D.C0 * CFrame.fromAxisAngle(Vector3.new(0, 0, 1), math.rad(factor))
wait(0.0000001)
end
end)
spin()
end
function tweenC0(obj, angle)
local tweenInfo = TweenInfo.new(
0.2,
Enum.EasingStyle.Linear,
Enum.EasingDirection.InOut,
0,
false
)
local properties = {
C0 = CFrame.fromAxisAngle(Vector3.new(0, 1, 0), math.rad(angle))
}
local tween = tweenService:Create(obj.Motor6D, tweenInfo, properties)
tween:Play()
end
function turnWheels(direction)
local factor
if direction == "Right" then
factor = 45
elseif direction == "Left" then
factor = -45
else
factor = 0
end
local turnW = coroutine.wrap(function()
tweenC0(wheels.FrontRightWheel.PrimaryPart, factor)
tweenC0(wheels.FrontLeftWheel.PrimaryPart, factor)
end)
turnW()
end
Is there any way this can be resolved?