My raycast car suspension won't stop going forward

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? im trying to make a raycast suspension car

  2. What is the issue? for some reason the car keeps moving forward instead of standing still

  3. What solutions have you tried so far? I did several tests with the physics of the car and with the code but no matter what I do it always leans forward.

here is a video of the car:

here is the video that im using: Making Custom Car Physics in Unity (for Very Very Valet) - YouTube

and here is the code that im using:

-- Chassis is the main part of the car
-- Settings is a folder with the car settings

if raycastResult then
            local Force = 0
            
            local Offset = 0
            local Velocity = 0
            
            -- calculates the raycast offset
            local dist = (origin - raycastResult.Position).Magnitude
            Offset = Settings.Height.Value - dist
            
            -- calculates the spring velocity
            local springDiretion = Chassis.CFrame.UpVector
            local worldVelocity = Chassis:GetVelocityAtPosition(origin)
            Velocity = springDiretion:Dot(worldVelocity)
            
            Force = (Offset * Settings.Strenght.Value) - (Velocity * Settings.Damping.Value)
            
            Chassis:ApplyImpulseAtPosition(springDiretion * Force, raycastResult.Position)
        end

I found that the car always goes forward, regardless of whether attachment in the front

ok i’m so dumb, the attachments weren’t lined up correctly causing the car to go forward

before was something like this:
image

now it is like this:
image

i tried to fix this for 3 days lol

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.