5
\$\begingroup\$

If I sat down long enough, I'm sure I could make this happen, but I don't want to reinvent the wheel if I don't have to, especially if XNA has patterns in place for doing this.

For now, I'm working in a very low resolution world, minecraft style. Everything is a simple cube that's 1x1x1. Currently I can move and look around but the camera is floating above the cubes, it doesn't use the cubes to determine where the camera is or where the camera should not be.

I'm just looking for the simplest of physics, such as not walking through blocks, if I walk off a cliff the character (camera) should fall and land the proper height above the ground, and general movement physics that you would expect out of even the most basic of games.

My first approach was to have a BoundingSphere for the character and a BoundingBox on each cube but when I detect a collision between the sphere and any box, how do I correct the character's placement to not intersect anymore?

I'm open to any alternatives and techniques that are out there.

\$\endgroup\$
1
  • 5
    \$\begingroup\$ "especially if XNA has patterns in place for doing this" - to my knowledge, XNA has no pre-built-in for game-logic, only rendering/audio/input. However, you might be able to find some useful examples in the MSDN XNA catalog. \$\endgroup\$ Commented Jun 17, 2011 at 15:48

1 Answer 1

1
\$\begingroup\$

Well normally I'd recommend you read a book about game engine physics, like the book 'game engine physics', but since you want it to be very simple I would suggest this:

Define a gravity constant. Every frame, attempt to move the camera downwards with that constant. if the camera intersects with any block, using boundingboxes/spheres. Have your collision detection also return how far your sphere intrudes into the block (in the case of 1px blocks I would advice you group them together for the sake of collision detection) and just move your camera back up the amount of intrusion. If you want to be like minecraft, do damage to your character relative to how much intrusion took place.

Note that if your character falls from a high cliff or something like that, it might go so fast it goes through a block in less than a frame, causing you to miss the collision, for this you might want to stretch the boundingbox/sphere between the last frame and the current frame.

Note these are all very 'arcade' physics suggestions, they are not realistic at all and will most certainly fail in more complex environments.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .