Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Collision Detection in a GTA style game

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, everybody I''ve been trying to create a GTA-ish game for some time now, but ran into one big problem: Collision Detection. Could anybody explain me how to do is in a simple way in a gta-ish game. --- marius http://fr.ee/linux

Share this post

Link to post
Share on other sites
Grand Theft Auto.

GTA is essentially a 2D game with a 2D map. Therefore you could have a Quadtree holding your map. Buildings would be held in the leaves and they would be set out as a series of rectangles (In GTA they are always axis aligned). This would be easy to do collision detection on and you''d get the benefit of only drawing whats on the screen for virtually free.


Share this post

Link to post
Share on other sites
Guest Anonymous Poster
Ok buddy. I know what you mean and I can help.
Here''s an example for ya.
Let''s say that two cars (carA and carB) have the coordinates carAX, carAY, carBX, carBY. (I hope you use arrays if you have a multitude of cars) This is an example for if your cars are the exact same size in pixels. And let''s say they are 100x100 pixels.

To detect a collision:

/* Detect with X coordinates */
if ((carAX <= carBX && (carAX+100>=carBX)) ||
((carAX+100)<=(carBX+100) && (carAX+100)>=carBX))

/* If there is an X collision, detect a Y collision */
if ((carAY <= carBY && (carAY+100>=carBY)) ||
((carAY+100)<=(carBY+100) && (carAY+100)>=carBY))

This is just a simple example.


Share this post

Link to post
Share on other sites
I belive GTA uses 2 dimesional collision detection.
So it checks for which tile is in the man''s/car''s direction in the map:



const float piover180 = 0.0174532925f;
float distance;//distance ahead to check
//from man
int angle; //angle of man or car to move
//in degrees
POINT position;//position (on screen) to be checked
//for tile

position.x = sin(angle*piover180) * distance;
position.y = cos(angle*piover180) * distance;

end code.

-You might know this already. If you don''t I hope you can use it I don''t now have time for more spec.infor.



Share this post

Link to post
Share on other sites
I think I remember gta used a height-map.
so it''s actually some kind of 2d/3d mixture. that means there are no walls etc. blocking objects are actually just very high grounds.
so you might wanna save the current height and when the player tries to enter another tile check if it''s at the same height.
gets more difficult when driving a car, though... since cars take up more space than one tile


Share this post

Link to post
Share on other sites
i havent properly implemented my collisons in my game yet (its also a gta like game) but when i do, theyll be using "line crossing another line" detection, rather than points on the vehicle, as its not accurate and effective enough for me

i forget the name of this vector/plane crossing method, maybe someone can remind me

graham "red" reeves.


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!