#### Archived

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.

## 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 on other sites
Okay, this may sound stupid but what is a GTA style game?

##### 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.

Pete

##### Share on other sites
don''t you know Grand Theft Auto?
you really missed something... but i''d also love see a constructive comment!
SnAkE''s Programming Resources

##### Share on other sites
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))
/* WE NOW HAVE A COLLISION */

This is just a simple example.

NapalmB

##### 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:

code:

#include

const float piover180 = 0.0174532925f;
//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.

/Atte

/Atte

##### 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

nik

##### 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.

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5

• 11
• 12
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
633348
• Total Posts
3011463

×