I’m currently working on a custom car chassis, and I need the wheels to rotate.
I’m using TweenService and Orientation(vector3) to rotate them with the Steer inputs, so it becomes something like “Steer * self.Engine.Orientation”, it works fine but the problem is, that when the multiplying makes it go past 180 degrees, instead of of making it go at -180, it goes at 190; making the wheels go crazy and spin
Heres a vid showing when I drive the car at the 180 world space orientation, the wheels spins
This might just be super easy to solve lol but I have tried other methods to making the wheels move like CFrame, but it dosen’t work unless I anchor the Wheels
like math.clamp? it wont work because it gets stuck there until the car orientation switches over to -180 from 180, the steer can be ahead like for example 200 if the car orientation is 180, beause of the equation
I did make a car chassis before (actually, several of them), and had success with something similar to this. What I did is I modified the CFrame of the weld from the base to the wheel in object space. I never used TweenService to modify the CFrame.
Well, for steering I did weld.C0 = weld.C0:Lerp(targetCFrame, 0.1)
and it looped on Heartbeat in a LocalScript. I made a Script that did the same thing on the server, but didn’t run on Heartbeat and did not lerp.
Set the acceleration to 0.1. If you constantly lerp something 10% closer to its goal, it will travel there exponentially. It’s just an alternative I use to TweenService’s Exponential EasingStyle. If you want it to go into a certain position, you must use FuzzyEq and a Vector3, although I don’t think this is necessary as you can always question the CFrame target value.
I wouldn’t do either of those, but you can keep your existing code and use ToObjectSpace(), because Welds use object space.
Basically, I used math.rad and a certain angle of CFrame to get steering to work, but I forgot which direction it was in. The CFrame handled both the suspension and steering, and the suspension was handled in world space and the steering in object space.
So, I did put the suspension in object space, I had a dedicated WheelScript that had a value called currentDistance that was constantly fed information by the main script, which handled the suspension and everything.
So, don’t use ToWorldSpace or ToObjectSpace. It should be in object space to begin with. Also, you don’t need to add a Vector3 into a CFrame. Just use the 3 arguments of the CFrame.new(x, y, z) function.
The lerping stuff is simple. Make an empty CFrame that is just a local variable, and change that as needed. Then, add a loop that will change the CFrame of the weld all the time (or when it is changed), which will lerp the Weld’s CFrame to the target CFrame.
Other than that, I think you got it! I hope the project comes together nice and smooth.