Yep. I just erased the entire script since I wanted to turn it into something usable. I managed to find the backed up version.
Well I think we have a solution, @VineyardVine. I think @nooneisback just remade your whole suspension system the right way!
What are the motor6Dâs for, and can I turn the wheels to cylinders for cars?
Motor6Dâs are basically the same as Welds, but they are favored for some reason and much less likely to be deprecated. You can probably make them spin by changing the C1, though I really donât want to deal with that right now. Welds are confusing without a sheet of paper and an hour of thinking.
How do you change the height of the suspension on:
There is a config module inside the script which contains the properties. Change the Spring.MaxLength. I donât know if itâll change the height of the wheels though, since I welded them manually after writing the base of the script.
It does change the height of the wheels.
How can I fix it?
Fix it in what way? The wheels are updated per Heartbeat according to the distance of the hitpoint/spring length (if no surface below) and offset back by their radius.
But when I change the Spring.MaxLength in the Modulescript, the wheels are lifted above the ground as well. So the wheels will never be touching the ground. (Change the MaxLength to 10, and you will see what will happen)
Alright, thatâs what I feared.
In the function connected to the Heartbeat, there is a segment of code that is something in the lines of âWheel.Weld.C1â. Change it to Wheel.Weld.C0 = CFrame.new(0,-dist+whrad,0).
Is it at line 67?
30Characters
To make them spin, youâll have to turn velocity of the wheels that touch the ground into angular velocity and multiply by dt.
if Pc then
Wheel.Weld.C0 = Wheel.Weld.C0 * CFrame.Angles(root.Velocity:Dot(nlv)*whrad*dt,0,0)
end
Not sure if itâs correct, but should be.
Place it after the height update.
Donât have the place open RN, so Iâll have to tell you probably.
I fixed the issue and it is now:
whdyndata[2].Motor6D.C1 = CFrame.new(0,-dist+whrad + 3,0)
at line 67
The only problem that it has now is when a wheel is above the ground, it will go back up to the thruster.
I uploaded a fixed version. The only concern I have is how to balance the stiffness and vehicle mass. Too much stiffness makes the car unstable, not enough makes it wobble around when a player is standing on it.
Is there a math equation that we can use to determine the right stiffness then?
Just out of curiosity
Hookeâs law is an equation to calculate the force exerted by the spring in case of an offset.
F=k*x
Weight is an action force that a body of a defined mass applies to a surface it is on.
F=m*g
You can calculate the minimum stiffness by checking the case where both forces are equal and stay at a fixed offset.
k*x = m*g -> k = m*g/x
Now you just add the stiffness until you get a perfectly stable vehicle under load.
The only issue is that everything is calculated in studs instead of meters, so you might get some absurd results. NVM, the results are crazily off.
I have had to deal with this a lot in the past year or so, I have open sourced the file I managed to successfully do this with and I can post a link here once I have access to a computer if interested.
DT
stands for delta which means the difference in two values(Change) in this case, Time.
The wait function returns exactly how long it waited for. So the code would look something like this
function wait(Time)
local StartTime = tick();
--Yielding Code
return tick() - StartTime;
end
The wait value takes a hefty majority of the computing time to the point where everything else happening in the loop is insignificant. So if the wait returns the significant difference between the time of the loop was last calculated then itâs safe to use it as the Delta value. The difference between using the Delta value supplied by Heartbeat
or RenderStepped
is how often it runs and, in this case, slightly more accurate timing.
It also eliminates the need for calling tick() on each frame.