Make Z-axis not used?

Mar 26, 2008 at 10:48 PM
Edited Mar 28, 2008 at 12:31 PM
I'm building an sidescrolling game but with 3D models/graphics/maps to create depth. Therefore I want positions and rotation to be in 2D only (removing the Z-axis) OR setting all Z-axis to zero in affected places (f.ex. Body() etc) but let the calculations still be in 3D.

Which classes do I need to change to achieve this? Should it be possible changing the PhysicsSystem() class alone or should I change other classes, f.ex. Body() and CollisionSkin(), instead?
Coordinator
Mar 29, 2008 at 3:14 PM
You should write a constraint which doesn't allow bodies to move into z dir.
Mar 31, 2008 at 11:51 PM
Edited Apr 2, 2008 at 7:58 AM
Had completely missed the constraint-functionality! Nice for sure.

body = new Body();
ConstraintVelocity vel = new ConstraintVelocity(body, ConstraintVelocity.ReferenceFrame.Body, ?, ?);

Could you, or anyone with knowledge about how to specify the vectors, help me out how to write a constraint that disallows the body to move into Z-direction and make it unable to rotate on the X- and Y-axis?
Coordinator
Apr 2, 2008 at 10:13 PM

Zenox wrote:
Had completely missed the constraint-functionality! Nice for sure.

body = new Body();
ConstraintVelocity vel = new ConstraintVelocity(body, ConstraintVelocity.ReferenceFrame.Body, ?, ?);

Could you, or anyone with knowledge about how to specify the vectors, help me out how to write a constraint that disallows the body to move into Z-direction and make it unable to rotate on the X- and Y-axis?


I don't think its going to be as easy as using ConstraintVelocity... thought i'm not expert on constraints...

How I'd approach the problem is to create a now constraint that undoes any z axis movement.

A simple way to do this would be to take ConstraintWorldPos but adapt it so the 'world point' is the input bodies X,Y position with Z = 0. The code in that class should work out the correct inverse impulse to undo any Z movement, so satisfing your constraint...
Apr 3, 2008 at 7:27 AM

DeanoC wrote:
I don't think its going to be as easy as using ConstraintVelocity... thought i'm not expert on constraints...

How I'd approach the problem is to create a now constraint that undoes any z axis movement.

A simple way to do this would be to take ConstraintWorldPos but adapt it so the 'world point' is the input bodies X,Y position with Z = 0. The code in that class should work out the correct inverse impulse to undo any Z movement, so satisfing your constraint...

Looked at it further and it seems like it's not possible by just using ConstraintVelocity as you said. Going to make another class based on ConstraintWorldPos and change it somewhat, that ought to fix the problem with objects moving along the Z axis. Should be pretty easy I guess.

But how I'm going about to stop objects from rotating around the X- and Y-axis is a mystery to me. If anyone got some ideas on this one I would be happy to try and test it out. Anyone?
Apr 15, 2008 at 5:05 AM
I don't think you can expect accurate collisions from a 3D engine if you constrain everything to 2D. You might be better off using a 2D physics engine and adding 3D to the rendering of the whole thing.
Apr 15, 2008 at 9:36 AM

LordIkon wrote:
I don't think you can expect accurate collisions from a 3D engine if you constrain everything to 2D. You might be better off using a 2D physics engine and adding 3D to the rendering of the whole thing.

That's another thing I'm testing atm. It has it's difficulties as well, but hopefully I'll get something going so that the basic functionality of the game is up pretty soon. You could probably be right about that it's better to use an 2D physics engine and adding 3D rendering to that one instead of 3D all the way but limiting that solution to 2D axis only though. Should know in a short while I hope.
Sep 16, 2009 at 10:42 PM

could someone solve the constraint thing on the Z axis?

by the way...I have an object that I would like to limit its rotation within a range around certain axis....is this the same kind of scenario? how do i do that?

 

thanks!!!

jiglibx rules!

Jul 8, 2010 at 1:43 PM

This is how I did it, I implemented this code into my character's body class.

Vector3 zPosLock = Position;
zPosLock.Z = 0.0f;
Position = zPosLock;

This code constantly resets the Z position of the character to zero.

Might not be elegant but it's functional.