I’m working on a raycast suspension and I got it to work but when the player stands on top of it, the car starts bouncing out of control
here’s a vidoe
here’s my code just in case
local worldPosition : Vector3 = attachment.WorldPosition
local vectorForce : VectorForce = attachment.VectorForce
local rayDirection : Vector3 = -mainBody.CFrame.UpVector * (springLength + wheelRadius)
local raycast = workspace:Raycast(worldPosition, rayDirection, rayParams)
local springLength = 3
local wheelRadius = 0.5
local stiffness = 2000
local damping = 15
-- [ suspension force ]
if raycast then
local springDir : Vector3 = mainBody.CFrame.UpVector
local worldVelocity : Vector3 = mainBody:GetVelocityAtPosition(worldPosition)
local rayDistance : number = (worldPosition - raycast.Position).Magnitude
local offset : number = (springLength - rayDistance)
local velocity : number = springDir:Dot(worldVelocity)
local force : number = (offset * stiffness) - (velocity * damping)
vectorForce.Force = springDir * force
end
any thoughts on why its doing this and how I can fix it?
Have you tried setting the Model’s PrimaryPart’s NetworkOwnership to nil (the server) and running the script on the server? This will make the server run the physics. And then once you are seated and driving the car, set the NetworkOwnership to the driver and run the script on the client.
I also have other problem but I think it happens when I set the springlength to 5, and when the rays hit a block, the car spins out of control and flys upwards