Sign in to follow this  
KevArnold

Game movement / collision

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 this post


Link to post
Share on other sites
Quote:
Original post by KevArnold
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.


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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this