# Question PhysX not doing it to me

Discussion in 'Physics' started by henners999, Mar 10, 2023.

1. ### henners999

Joined:
May 30, 2020
Posts:
21
Quick, potentially daft question: I'm moving from 2d physics to 3d, Box2d to PhysX, for my driving game. In box2d I could get some real weight and momentum behind my vehicles using simple calculations but PhysX seems lightweight in comparison. I've looked through every advanced simulator on the asset store and they all have this trait.

To me it seems as if there is a lack of inertia, the rigid body seems to resolve the forces acted upon it too quickly. At least that's how I see it. Is there a way to increase this inertia? Increasing mass didn't seem to do it for me, neither did reducing grip. I have tried wheel colliders and ray casting.

Any guidance welcome!

2. ### arkano22

Joined:
Sep 20, 2012
Posts:
1,503
Both engines use real-world units, and under the hood they're more or less comparable (both are iterative, velocity-based, maximal-coordinates based engines).

Inertia is "implemented" the same way in all engines: a = F/m. The larger the mass of an object or the weaker the force applied to it, the less its velocity will change as a result. So if you have two objects of different masses and apply the same force to both, the heavier one will exhibit a lot more inertia.

It's hard to say without looking at an actual example of your problem, but simply increasing the mass of your rigidbodies *should* do the trick.

Last edited: Mar 10, 2023
3. ### Edy

Joined:
Jun 3, 2010
Posts:
2,361
Additionally/alternatively, you may apply a multiplier to the inertia tensor, Rigidbody.inertiaTensor. This will increase the rotational equivalent for mass, slowing down the rotation rates of the rigidbody for the same mass and force.

4. ### henners999

Joined:
May 30, 2020
Posts:
21
Oh cool thanks I'll give those a try. I think it'll be trialing all the different methods of creating a car then finding the best one that'll be the answer.

5. ### henners999

Joined:
May 30, 2020
Posts:
21
Is there a way to attach 4 rigid bodies solidly? I've tried hinge joints and configurable joints but the wheels wobble around (hinge) or are overly complex (configurable). Is the joint system not built for such a task or am I doing it wrong?

Help!

6. ### arkano22

Joined:
Sep 20, 2012
Posts:
1,503
Depends on what you mean by "attach". If you just want objects to keep their relative position/orientation, FixedJoint should do the work.

This doesn't work for wheels if you want them to rotate, however (unless you're faking rotation using textures or any other method). I case you don't want to constrain rotation, HingeJoints should work pretty well. It's hard to tell if you're doing something wrong without knowing anything about the way you've set them up, though.

Also note that in many cases you don't need the wheels on a car to be rigidbodies. In fact, rigidbodies are not a good representation of a wheel at all. Using a simple spring is often a lot better, and implementing your own tire friction will give you much better results. Here's some info about this approach:

7. ### henners999

Joined:
May 30, 2020
Posts:
21
Thank you for the information. I've seen that video, to reiterate, could you explain how the wheel turns if the ray cast is just a sensor?

For some context, my game is completely top down so the wheels don't need to rotate. I just need a system where I can model the frictional forces on each wheel myself. Don't specifically need suspension modeled at all.

I'd also like to restrict the y axis so the car sticks to the ground unless I tell it to. Constraining the y axis currently pings my car off every which way but loose.

8. ### arkano22

Joined:
Sep 20, 2012
Posts:
1,503
You could just take wheel displacement ((pos - oldPos) / deltaTime) and convert it to a rotation: 2*pi*radius is the circumference of a circle - aka, distance traveled in one full turn- so just divide the displacement by this and you get the amount of revolutions.

Just make the spring work in both directions: separate the car from the floor if too close, but also bring the car closer to the floor if too far away. This is explained in this other video, in the context of character controllers:

9. ### henners999

Joined:
May 30, 2020
Posts:
21
Thankyou so much for your help. I've managed to get a raycast setup like the one from the above game and your idea to keep the car grounded is fantastic. I think raycasts are the way forward as they are simple and efficient and don't involve messing around with random numbers. I think a big thing that got in the way of my understanding was how intangiable they are. I mean each ray is just an empty object. Once I understood that it helped a lot!

One thing, as the raycast has no weight, how would you model unsprung mass as that has quite an effect on the handling of a car?

Last edited: Mar 27, 2023