Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
5  
"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. –  BlueRaja - Danny Pflughoeft Jun 17 '11 at 15:48

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.