Hello, i’ve started integrating PhysX into my graphical engine recently(purpose is basic collision with level, which is represented by static primitives and some debris, like cans, barrels and bottles reacting at bullets and impact with a player). Currently done is representing the scene with static primitives and using convex hulls for dynamic actors. And at this stage i’ve noticed PhysX acting not exactly like one would expect. I’ll try to describe it as verbose as possible, and i would like to hear some logical explanation and advice.
My initial setup was:
Timestep 1/30.0f, called in a separate from rendering thread, which runs at 30 FPS. Called exactly, as an example from documentation.
Gravity: Y = -9.8
Material for static actors: 1.0f, 1.0f, 0.5f (static friction, dynamic friction, restitution)
Material for dynamic actors: 0.5f, 0.5f, 0.3f
Static actors don’t have any other parameters. All actors are positioned and scaled correctly, checked it through PVD.
As for dynamic actors:
setMass(PxReal(Objects[f].weight)); //currently 1-30 for different objects
i also set setCMassLocalPose to model’s relative center(because some models may be not centered correctly).
First of all, i would expect to just set object’s mass in kilograms, or at least relative to other objects, with default gravity of -9.8 and timestep of 30. Neither worked. Objects with mass of hundreds or thousands kilograms end up falling through the floor or bouncing crazily. And smaller objects with lower mass were too floaty.
At first, all big\medium-sized objects were freaking out. And by looking at PVD’s grid in comparison with my scene, i figured i need to rescale my scene. My level is up to 3000 by 3000 units size. Medium-sized object is 20-30 units, and small object is around 2-4 units of size. So in process passing physical objects to PhysX, i now rescale them and their positions by some factor(now it’s 0.05f). And it made things better.
But there are significant problems remaining. First thing i don’t get is why scene get’s slo-mo, if i decrease time step size. PhysX Tips page says “Few substeps: moon gravity effects”, so it’s vice-versa.
Actors with bigger mass still act inadequately.
Different scaling factor affects simulation speed. So setting scale to a smaler value, makes everything move more rapidly and with less inertia\bounce. With smaller scene scale, smaller objects act like they have enormous friction or low bounce\angular velocity.
And that leads to the main problem i can’t solve yet is that with scene, rescaled by 0.05f smaller objects(like soda can or a pack of cigarettes) act really floaty. They don’t react well on collision, they rotate too slowly and don’t bounce. I have a scene with a character model, some barrels, a big box and soda can, represented with convex hulls. And environment, represented with boxes, spheres and capsules. I fly around and shoot spheres at them, and look how they react. Medium-sized objects have a mass of 20-30, and small objects have a mass of 5(yeah, i did mention relative mass inconsistency. if i put more appropriate relative weight to smaller objects, they act even floatier and don’t react much on a sphere with 100000 density and while falling, they act more like poo).
I just don’t want to fiddle with magic numbers. I would like to find some explanation and make it more predictable and consistent.
if that’s important, PhysX version is 3.2 and platform is Windows.