Page 1 of 1
Best way for 2D physics
Posted: Wed Aug 31, 2011 7:03 am
by Bonus
Which method is best for 2D physics? PointOnPlain? Two zero axises on InertiaTensor? Something else? What would better for windows phone 7? How to make a switchable 2D-3D modes for a single entity?
Re: Best way for 2D physics
Posted: Wed Aug 31, 2011 5:09 pm
by Norbo
It depends on your goals and performance requirements.
A PointOnPlaneJoint can restrict an entity's linear movement. You could technically use a RevoluteAngularJoint, which removes two degrees of freedom, to handle the angular movement without touching the inertia tensor, though changing the inertia tensor is quick and robust.
Linear motion could be constrained 'manually' as well. Setting its position every frame such that it doesn't deviate from the plane while also correcting its velocity to remove all motion along the plane's normal would do the trick. This would be faster than a PointOnPlaneJoint, but less robust in difficult configurations. If 3D mobile objects are able to collide with the 2D-bound objects, the PointOnPlaneJoint may be needed to keep things robust- or not! It depends on what you need, test and find out

To switch from 2d to 3d linear motion, simply remove the PointOnPlaneJoint or stop controlling its position/velocity manually.
Zeroing out two axes of the LocalInertiaTensorInverse would indeed keep an object from rotating around those two axes. This is the fastest approach for controlling angular motion because it doesn't do anything extra. However, you should keep the 3d and 2d versions of the LocalInertiaTensorInverse cached so you can quickly reassign them when the entity changes from 2d to 3d and vice versa. Recalculating inertia tensors can be expensive depending on the shape.
Re: Best way for 2D physics
Posted: Wed Aug 31, 2011 5:55 pm
by Bonus
Perhaps you could make a new limit for the 2D physics as part of the engine?
I think this is a very common task for the games.
Re: Best way for 2D physics
Posted: Wed Aug 31, 2011 5:59 pm
by Norbo
A PointOnPlaneJoint + RevoluteAngularJoint is a 2D constraint. I suppose I could toss something in, but it would be purely for trivial convenience. It wouldn't be doing anything special.
An argument against doing this is that not every game should or could use the constraint approach. I'd rather not be responsible for implementing every possible option for every game. Also, the engine's focus is 3D

Re: Best way for 2D physics
Posted: Thu Sep 01, 2011 6:18 am
by Bonus
I mean a constraint that would work through the inertia tensor with caching and switching 2D-3D. Easy and fast tool that can be used even on the phone. Because I think that adding 2 constraints per entity on the phone is not a good idea.
Anyway thank you.