2D world constraints

2D world constraints

Bild des Benutzers samaursa

I am creating a game that is a top down space shooter. It is in 2D, therefore I have constrained the rotations of the objects so that it can only rotate in the Y-axis. I also want them to always be at Y = 0; even if they manage to somehow get on top of each other, I want them to 'fix' their positions.


I have been reading the forums and there is a post about 2D games and the recommendation was to use a point to plane constraint. I went over the demo but it confused me. If someone can clarify and explain how to set up the point to plane constraint (especially given my case) I'd be grateful. Thanks!
5 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.
Bild des Benutzers PatrickAtHavok

Hi there Samaursa

It's pretty much exactly what it says on the tin: like in the demo, use the hkpPointToPlaneConstraintData::setInWorldSpace() to set up the transforms of the plane and point, and the plane normal, for the constraint data (line 129 of the demo), then make a new constraint between your rigid bodies (you'd use something fixed, like we do in the demo, to keep your plane normal to the view direction) using the plane constraint data (line 135). Add it to the scene and you're done.

If you want everything in your game to be on the same plane, just make a separate point-to-plane constraint linking each entity in your game to the same plane by its center of mass or some suitable place. If you're careful about how you choose your pivot points, you can even re-use the same constraint data for multiple constraints.

Patrick Developer Support Engineer Havok www.havok.com
Bild des Benutzers samaursa
Quoting - PatrickAtHavok Hi there Samaursa

It's pretty much exactly what it says on the tin: like in the demo, use the hkpPointToPlaneConstraintData::setInWorldSpace() to set up the transforms of the plane and point, and the plane normal, for the constraint data (line 129 of the demo), then make a new constraint between your rigid bodies (you'd use something fixed, like we do in the demo, to keep your plane normal to the view direction) using the plane constraint data (line 135). Add it to the scene and you're done.

If you want everything in your game to be on the same plane, just make a separate point-to-plane constraint linking each entity in your game to the same plane by its center of mass or some suitable place. If you're careful about how you choose your pivot points, you can even re-use the same constraint data for multiple constraints.

Thanks for the reply Patrick. I think I'll have to read up more about Constraints in the docs and follow more examples as I am confused by some aspects of the point to plane constraint (for example, why do we need a fixed body [we are already passing an up vector, which will be the planes normal] and why do we need to constrain the moving body with a fixed body if all we want is to constrain it to the plane)
Bild des Benutzers PatrickAtHavok
Best Reply

Hi again Samaursa

This is a direct result of the internal mechanics of the constraint solver implementation, which needs two bodies to function. A useful side effect of this is that it is more general this way. With our implementation, it is possible to make sure that something stays tethered to, for example, one face of a rolling cube or something like that (yet free to move about that face).

You don't have to create a new rigid body for the fixed one, either - there is one (hidden) fixed rigid body that is always created at the same time as the world, and you can set it as the fixed body for your constraint by passing NULL for entityB in the hkpConstraintInstance constructor. This comment can be found here in the documentation: Reference Manual -> hkpDynamics -> Classes -> hkpConstraintInstance (look under the heading, Constructor & Destructor Documentation)

Patrick Developer Support Engineer Havok www.havok.com
Bild des Benutzers samaursa
Quoting - PatrickAtHavok Hi again Samaursa

This is a direct result of the internal mechanics of the constraint solver implementation, which needs two bodies to function. A useful side effect of this is that it is more general this way. With our implementation, it is possible to make sure that something stays tethered to, for example, one face of a rolling cube or something like that (yet free to move about that face).

You don't have to create a new rigid body for the fixed one, either - there is one (hidden) fixed rigid body that is always created at the same time as the world, and you can set it as the fixed body for your constraint by passing NULL for entityB in the hkpConstraintInstance constructor. This comment can be found here in the documentation: Reference Manual -> hkpDynamics -> Classes -> hkpConstraintInstance (look under the heading, Constructor & Destructor Documentation)

Thanks a lot for the clarification Patrick!

Melden Sie sich an, um einen Kommentar zu hinterlassen.