Sign in to follow this  
animator

PhysX bouncing cubes

Recommended Posts

Hello. I wonder if anyone else has this problem using PhysX. When I make a cube, align it with the axis, and drop it from a height it bounces up and down but then when its nearly comes to rest it tumbles over. Also if I make several cubes and align them in the same plane when they interact some of them come out of that plane. Surely if a box is aligned upright it should never always simply bounce up and down and not tumble over. Is there something I am doing wrong or is this a feature of PhysX? I have the restitution for the box and plane on about 0.8 What I am trying to do is make a 2D game so I want all the boxes in the same plane and not come out of that plane or tumble unexpectedly. Any ideas?

Share this post


Link to post
Share on other sites
PhysX or any physics engine for that matter allows unconstrained motion in all 3 dimensions. Due to the inaccuracy of floating point numbers and numerical integration, after some length of time it is almost given that objects will not behave exactly as you expect them to.

It seems like what you're trying to do would be better done without the use a physics engine - or at least without the engine controlling how the bouncing objects move. If all you want is to have a cube bounce in a 1 dimensional fashion up and down, there is no reason why you can't just program this movement explicitly, rather than trying to coerce the physics engine into doing something that it wasn't intended to do.

Share this post


Link to post
Share on other sites
As Aressera said, due to floating point inaccuracy, you can't really trust that the motion is always correct in the plane.
One possible solution is to use the very powerful PhysX 6dof joint, build a special constraint that "lock" one translational dof, and also two rotational dofs (in 2d only one rotation is allowed), apply the same kind of constraint to all the bodies of your simulation. But you should also be aware that this isn't a very elegant solution: forcing a 3d physics engine to be a 2d one.
My best suggestion is here: www.box2d.org this is a very nice and robust 2d physics engine. It offers the same features as physx does, but for a 2d physics simulation.
hope this helps
cristian

Share this post


Link to post
Share on other sites
Thanks, I wonder if Havok has the same problems? Maybe PhysX is not really as accurate as it is made out to be.

I'll take a look at that 2D physics engine. It looks interesting.

edit:

I've found away round this by manually setting the position, velocity, z-components to 0 and the x/y components of the orientation-quaternion and angular velocity to 0 in each time step. It seems to work OK but probably not the best thing to do as I don't know what errors this might build up.

[Edited by - animator on July 27, 2008 5:36:15 PM]

Share this post


Link to post
Share on other sites
Well... in general physics engine usage, forcing the velocities is a very bad thing to do. If you want to keep using physx, you would probably do what I already wrote: using some of the tool provided by the engine (eg: configurable joints) to do the job for you.
If I were you, I would go for the 2d physics engine I suggested in the previous post. It's really really good.
cheers.

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

Sign in to follow this