Jump to content
  • Advertisement

Raycast suspension at high physics time step problem.

Recommended Posts

I am creating a simple raycast car, it work fine at 0.01 fixed time step but the suspension is very unstable at the higher time step, i want it to work well at 0.05.
Does anyone have ideas to solve this?

Share this post

Link to post
Share on other sites

You could also add some additional damping to your suspension to avoid the instability, if that works for your application.

Share this post

Link to post
Share on other sites

Thank for your help, but i am finding a way to make it work the same at high time step, not to change the property to adapt the time step.
And here is my current suspension code.

private void SuspensionUpdate() {
		spring.preOverflow = spring.overflow;
		spring.overflow = 0f;
		if (grounded && Vector3.Dot(hit.normal, transform.up) > 0.1f) {
			spring.bottomedOut = spring.overExtended = false;

			spring.length = transform.position.y - hit.point.y;

			if (spring.length < 0f) {
				spring.overflow = -spring.length;
				spring.length = 0f;
				spring.bottomedOut = true;
			} else if (spring.length > spring.maxLength) {
				grounded = false;
				spring.length = spring.maxLength;
				spring.overExtended = true;
		} else {
			spring.length = Mathf.Lerp(spring.length, spring.maxLength, Time.fixedDeltaTime * 8f);

		spring.velocity = (spring.length - spring.preLength) / Time.fixedDeltaTime;
		spring.compression = (spring.maxLength - spring.length) / spring.maxLength;
		spring.force = spring.maxForce * spring.compression;

		spring.overflowVelocity = 0f;
		if (spring.overflow > 0) {
			spring.overflowVelocity = (spring.overflow - spring.preOverflow) / Time.fixedDeltaTime;
			spring.bottomedOutForce = parentRigidbody.mass * -Physics.gravity.y * Mathf.Clamp(spring.overflowVelocity, 0f, Mathf.Infinity) * 0.0225f;
			parentRigidbody.AddForceAtPosition(spring.bottomedOutForce * transform.up, transform.position, ForceMode.Impulse);
		} else {
			damper.force = spring.length <= spring.preLength ? damper.bumpForce * spring.velocity : -damper.reboundForce * spring.velocity;

		spring.preLength = spring.length;


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!