Collision Detection help for the self taught idiot...

Started by
5 comments, last by Glass_Knife 11 years, 4 months ago
Hi all,

I'm writing a basic Gravity Force 2 clone where players fly a ship around a level, fighting gravity and themselves.

I'm self taught and am learning what I need when I need it. So now I'm needing to learn basic collision detection.

Currently you can fly the ship around the map but you can go past the edges. The map is made up of large blocks (half the size of the players ship) and the player can (eventually) destroy them if they hit it hard enough and shoot them. But of course this doesn't work at the moment hence why the player can just fly for an eternity...

But how do I perform collision detection? Now since I am a total beginner please assume that I know very little of the mathematics behind this, as I said I'm teaching myself as I go. Unfortunately I'm one of those people that learns best by getting stuck in, making mistakes and then climbing out of them again.

So how do I perform basic collision detection (on basic geometric shapes) and what should I study up to understand these concepts?

Thanks for the help everyone!

Mike
Advertisement
A really easy quick way (That is not the optimal way of doing it) is to do collision detection is to keep a RECT of your ship as well as its previous location, also have RECT's for all of thing things you want to check collision with.

Every frame before rendering check if your RECT's intersect and if they do return the ship to its previous location you have stored before the render of that frame.

Now if you have a bunch of objects to colide with this approach may not be that best but its a great start if you are just learning.

Edit: I just noticed you tagged 3d, this advise was for 2d. Hopefully someone with more experience with 3d collision detection can weigh in for you :(
http://www.realtimerendering.com/intersections.html

The following site has a great list of the different kinds or intersections tests needed for
collision detection, and where to find more information. If you really want to get your hands
dirty, use the chart and implement all the different tests.

I think, therefore I am. I think? - "George Carlin"
My Website: Indie Game Programming

My Twitter: https://twitter.com/indieprogram

My Book: http://amzn.com/1305076532

I am self taught as well. Here is an example of how I do collision detection. It might not be the best of ways, but it does work.

if(objectA >= rightBoundary)
{
objectA -= 1;
}

if(objectA <= leftBoundary)
{
objectA += 1;
}

The distance away from the boundary or other object really depends on how far your objects moves. i.e. float, int, etc. and how much of a bounce effect you want it to have. If you have it move away considerably, it will look like you object bounced off of the boundary.

http://www.realtimer...ersections.html

The following site has a great list of the different kinds or intersections tests needed for
collision detection, and where to find more information. If you really want to get your hands
dirty, use the chart and implement all the different tests.
Thanks, that's a fantastic collection of sources.

I have just had the pleasure to use one of the mentioned books, Christer Ericson's "Real Time Collision Detection", to implement some basic collision stuff. Very solid book, recommended.
This link (GDNet user from Serapth) has some tutorials, including collision detection via bounding box, you should look at.

In general, you basically want to keep the position and dimension of your ship as well as the velocity, and check if the boundary of your ship has intersected the boundary of any of the collidible objects in your game every game loop.

If you have thousands of objects to check against, you might want to look into performing some broadphase collision 1st as discussed here. I would look at spatial hashing myself in this case, but do what you feel is right.

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)


I have just had the pleasure to use one of the mentioned books, Christer Ericson's "Real Time Collision Detection", to implement some basic collision stuff. Very solid book, recommended.


Recently I did a lot of work studying different intersection test methods. Between the internet, Khan Academy, Real-Time Rendering, and the book you mention above, "Real-Time Collision Detection" it covered everything.

I think, therefore I am. I think? - "George Carlin"
My Website: Indie Game Programming

My Twitter: https://twitter.com/indieprogram

My Book: http://amzn.com/1305076532

This topic is closed to new replies.

Advertisement