View more

View more

View more

Image of the Day Submit

IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Collision Detection help for the self taught idiot...

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

6 replies to this topic

#1Tset_Tsyung  Members

Posted 05 December 2012 - 08:35 AM

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

#2yewbie  Members

Posted 05 December 2012 - 09:37 AM

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

Edited by yewbie, 05 December 2012 - 09:38 AM.

#3Glass_Knife  Moderators

Posted 05 December 2012 - 09:46 AM

http://www.realtimerendering.com/intersections.html

The following site has a great list of the different kinds or intersections tests needed for
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 Book: http://amzn.com/1305076532

#4steffy81  Members

Posted 05 December 2012 - 10:03 AM

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.

#5Yrjö P.  Members

Posted 05 December 2012 - 10:42 AM

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

The following site has a great list of the different kinds or intersections tests needed for
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.

#6BeerNutts  Members

Posted 05 December 2012 - 10:49 AM

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)

#7Glass_Knife  Moderators

Posted 05 December 2012 - 11:24 AM

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