• Advertisement
Sign in to follow this  

Problem vehicle suspension formula - If damperForce is >0 then the vehicle is less stable...but It should be the opposite

This topic is 549 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

But, It should be the opposite. If damperForce is >0 then the vehicle is more stable...

 

The code:

// UNITY 5.4.0

//Constant values
float suspensionLength = 1.0f;
float stiffness = 0.4f;
float dampingForce = 1.0f;

void FixedUpdate()
    {
        RaycastHit hit;


       
        for (int i = 0; i < wheelPoints.Length; i++)
        {
            var wheelPoint = wheelPoints[i];


            if (Physics.Raycast(wheelPoint.transform.position,
                                -transform.up,
                                out hit,
                                suspensionLength,
                                layerMask))
            {
                float contactDepth = suspensionLength - hit.distance;
                float contactSpeed = contactDepth - lastContactDepth;
                float suspensionForce = stiffness * contactDepth + dampingForce * contactSpeed;
                suspensionForce *= 500;
                rigidBody.AddForceAtPosition(transform.up * suspensionForce, wheelPoints[i].transform.position, ForceMode.Force);
                lastContactDepth = contactDepth;
            }


        }
    }

Share this post


Link to post
Share on other sites
Advertisement

I thin it's simply a sign error. 

float suspensionForce = stiffness * contactDepth + dampingForce * contactSpeed;

The above line should really have been:

float suspensionForce = - stiffness * contactDepth - dampingForce * contactSpeed;

Cheers,

Mike

Edited by h4tt3n

Share this post


Link to post
Share on other sites

More problems there:

 

The spring speed is not only the difference of the the last and current position. You should multiply it with the timestep. (1/60 if your simulation runs at 60Hz)

 

suspensionForce *= 500;

 

This one seems to be a hack because of this:

 

float stiffness = 0.4f;

float dampingForce = 1.0f;

 

 

The 0.4 stiffness is too small, unless you are making RC cars, this value should be between 8000-10000 for street car, 30000-50000 for sports cars and around 200000 for a F1 car.

Also the damping should be much smaller than stiffness, maybe 10-20% could be a good start.

Later, if you want to be more fancy, real dampers have different characretistics with compressing (bump) and expanding (rebound). The bump should be smaller.

an example: when you drive over a bump, the wheel should react much quicker than when you drive into a hole.

 

Also what Mike wrote about the signs are correct, and you should check the signs of contactDepth and contactSpeed.

The depth should be negative when the car is on the ground, and the speed should be negative then the spring is compressing.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement