I notice that my raycast suspension doesnt add the wheelRadius, which means the ray is only goes to the length of the suspension length, so if the suspension length is 0, the car falls flat on the ground instead of it floating at the wheel Radius height
I’m not sure if that made since, here is some images
here are the car settings
as your see the spring length is 3 but the car is clearly not at the height of 3 plus the wheel Radius
in this image, as you see the red mark is how high the suspension should be, which is springLength + wheelRadius
heres is what I want, as you see the black ball represents where the springLength ends
and then the rest of the ray is the wheelRadius
This is what im trying to acheive. (a image from a youtube vidoe)
heres my code so far
local rayOrigin = attachment.WorldPosition
local rayDirection = -mainBody.CFrame.UpVector * (springLength + wheelRadius)
local raycast = workspace:Raycast(rayOrigin, rayDirection, rayParams)
local rayPosition = raycast and raycast.Position or rayOrigin + rayDirection
local rayDistance = raycast and (rayOrigin - rayPosition).Magnitude or springLength
-- [ spring force ]
if raycast then
local springDir : Vector3 = mainBody.CFrame.UpVector
local springOffset : number = (springLength - rayDistance)
local springVelocity : number = springDir:Dot(originVelocity)
local force : number = (springOffset * stiffness) - (springVelocity * damping)
springForce.Force = springDir * force
end
I don’t have much time left so ill be back in 6-7 hours, if someone can help me fix this, it’ll mean a lot to me.
feel free to take the code and test it on a simple part and make some visualizers for it and try to fix it