Setting up for collisions


The more I play with it, the cooler jME gets. I have a question regarding how one deals with collision detection. I’ve dealt with this sloppily when I did 2d game coding, I’m sure there’s a popular solution to it.

I have a thing on the screen (it’s a box). I keep track of its XYZ and let the player drive it around the game world. There are plenty of examples that show me how to realize when it’s stuck in a wall, but I’d like to know to deal with that.

I mean, in my update, I see the user is moving the box, so I do X += xVel. And that plants it smack in a wall. How do you deal with that? If I simply deny the movement, then the box will bounce without hitting the wall. Do I back it off along its path until it’s no longer colliding? Is this somehow handled in jME (its physics bit) or do we have to roll our own methods to deal with this? If our logic isn’t fixed-rate, this becomes even worse (such as bounces).



You could compute the first collisiding position for you box - computing the correct position for a box to contact with another box is not that hard. But when you start having more different objects and more complex objects you will have a lot to do…

I would recommend using jmephysics if you want collision and bouncing behaviour that looks ‘real’.

If you want to write simpler games like pacman and alike, I would recommend to abstract from actual geometry and maybe regard positions and distances only. (I don’t think there is something in jME to handle this for you)

Additionally you can mix those two and use physics with e.g. restricted velocities or positions…