# Game movement / collision

This topic is 3204 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I was wondering if someone could point me in the direction of common practices for motion and collision detection in game development. I am currently working on a 2d game with motion similar to Double Dragon. Currently what I am doing is just adding the current position with the entities velocity. I then test for collisions at the new position, if there is nothing blocking there I move the player. The problem is speed can make some it so certain entities can get closer to walls then other. What I am considering now is casting rays but how many rays is enough? If I dont cast enough I could miss objects in between the rays that I may hit? Or is there a way to cast the full hitbox?

##### Share on other sites
just use SDL an google Lazy foo very easy to follow an will cover all that

##### Share on other sites
Quote:
 Original post by KevArnoldCurrently what I am doing is just adding the current position with the entities velocity. I then test for collisions at the new position, if there is nothing blocking there I move the player. The problem is speed can make some it so certain entities can get closer to walls then other.

Well, what you want to do is basically detect the exact point of collision along the entire movement since the last frame and essentially iteratively move it to exactly that position.

Another problem you'll have with your current model is that really fast objects will pass through walls completely since they can move further in one frame than the wall is thick. A solution to this is swept-volume collision detection. Basically create a new piece of geometry that encompasses the entire space over which the object traveled since last frame.

You'll also run into problems with 2 objects with crossing paths who should have hit, but because of the quantization of their movement, did not.

Basically, it's a complex subject that's a pain to get right. This is why many people use 3rd party collision detection libraries. Box2D is probably a good fit for you if you're goal is to make a game rather than to make an engine.

If you're interested in continuing with your own solution I'd suggest picking up a copy of "Real-Time Collision Detection". May also be available on the web, so google around for it

-me

1. 1
2. 2
3. 3
4. 4
Rutin
15
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633724
• Total Posts
3013556
×