Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a wheel turn and rotate without counteracting each other?

Asked by 2 years ago

I've gotten quite far with my raycast vehicle, but I'm having problems rotating the welds on my wheels.  When I use the wheel steering or rotate wheels by themselves, they rotate in the direction I expect. When both are used at the same time, though, the rotation is thrown off. I believe that using world space or local space will resolve the problem, but I'm not sure which to use or how to implement it.

--Wheel Steering
            if string.find(wheelName,"F") then  
                    car[wheelName].Tire.Weld.C0 = car[wheelName].Tire.Weld.C0 * CFrame.fromAxisAngle(Vector3.new(0, 1, 0), math.rad(SmoothSteer * LimitSteering)) 
            end

--Rotate wheels
            wheelRotations[car] += LocalVelocity.Z/60
            local Rz = wheelRotations[car]
            car[wheelName].Tire.Weld.C0 = car[wheelName].Tire.Weld.C0  * CFrame.Angles(0,0,math.rad(Rz))

The wheel steering is applied first. https://giphy.com/gifs/LyYnnLWgmbhBS6C61M

Rotating the wheels (without steering) https://giphy.com/gifs/IWy0pOVnXiYDt3EyOZ

Both applied together https://giphy.com/gifs/GOR0cuwiP2xHKg6Yq8 As seen above this is not the expected behavior. I'm not looking for you to code it for me (what is shown is brief) just an explanation or pseudocode that would help me solve this.

Answer this question