Vehicle tends to roll in the air after hitting other entities

I am developing a racing game and I use the Vehicle Physics example provided by PlayCanvas.

The basic functions work well, but I find that when the car is going very fast and hits other entity with rigidbody component in the scene, the car is easy to fly and roll in the air.
This experience is not good, I want to make the car not easy to fly in the air, what can I do?

This is the Vehicle Physics example provided by PlayCanvas:
Overview | Dashboard | Vehicle Physics | PlayCanvas | 3D HTML5 & WebGL Game Engine

I tried to monitor the rotation Angle of the vehicle while it was moving and set the AngularFactor of the rigidbody component to 0 when the angle was greater than a certain maximum value to prevent the vehicle from continuing to rotate.
However, it seems that you can’t set the AngularFactor while the vehicle is moving, which can lead to non-stop rotation or other errors…

I dont know what I can do, please help… :smiling_face_with_tear:

Hi @928782280 and welcome!

If the problem is only on collisions with obstacles, you can maybe use lower values for the Angular Factor by default. You probably need to use higher values for the control of the vehicle in your script to compensate the difference.

@Albertos Thank you for your reply!

Unfortunately, there are some ramps in my scene, and reducing the the Angular Factor by default will make it impossible for vehicles to navigate on them.

Ah okay, I get it. I had some similar problems with my player controller on ramps. I spent some time finding the best balance for everything. I’m afraid you won’t get the perfect result, but maybe someone has a good suggestion.

Thanks so much.
And do you know if I can dynamically change the Angular Factor as the vehicle moves? I tried and failed, but I’m not sure if it was because of my methods…

It’s a vector 3, so I think it should be something like below.

entity.rigidbody.angularFactor = new pc.Vec3(1, 1, 1);

I don’t know if this will reset the rigidbody or current force.

1 Like

Generally, tweaking a vehicle controller is a labor intensive task. It is because it takes time to tune all parameters to make the vehicle behave correctly on your map. There isn’t one set of parameters that will match all terrains and environments, you have to tweak them to match your game. A single set of parameters can work great on one map and do a poor job on another.

Most common parameters to change:

  • wheel suspension params:
    • stiffness
    • damping
    • compression
    • rest length
  • change the center of mass position
  • vehicle mass
  • roll influence (how easy to roll vehicle over)
  • friction slip
  • rate of change of (how fast param is changing)
    • engine force
    • breaking force
    • steering

Those are default ones, but some games also implement additional features, like applying additional forces onto a vehicle to make it more stable on ground. Or adding supporting forces when in air, or using a shapecast instead of rays, etc.

The main problem is that changing even one parameter will affect others, so changing one would require you to change the others, making it a laborious process.

Yes, I have tried
but changing the parameter makes the motion of the vehicle even weirder,
so I don’t think I can simply change this parameter while the vehicle is in motion

I was aware of these parameters but didn’t use them because I didn’t really understand what they did.
There seems to be no better way. I’ll try it