# Thread: Solving Collisions in a car game

1. Member
Join Date
Aug 2010
Posts
16
Rep Power
0

## Solving Collisions in a car game

Okay, currently I have been making a car game and have started implementing powerups, the main problem is the fact that I just realised the way of detecting collisions is so inefficient that it is sickening.

Currently I am checking each powerup against each vehicle, and each vehicle against all others.

v(v-1)/2 + pv
(Where v is the amount of vehicles and p is the amount of powerups)

This is before I use the algorithms to check if they are even colliding (I cheated and used circles, 75% efficiencey... need better) (Checking the Hypotenuse of a triangle based on Pythragorus to the radius of the 2 objects).

This is before I have even implemented any tracks which will have walls and environmental obsticles.

Is there a much more efficient way (based on runtime) to check around the vehicles to see what it is colliding with? Should I set up a game grid and check the 9 squares around the vehicle?

Also anyone have any good ideas/examples of Square Colliisons in java?
Last edited by Rectal Exambot; 09-29-2010 at 05:38 AM.

2. Member
Join Date
Sep 2010
Posts
4
Rep Power
0
Hy, seems you need a concrete detailed implementation of a very complex problem. It is impossible to give a complete solution, at least for me. But a general, top level idea comes to mind:
A Car class could store a List of powerups. That way you can easily get them.
Another class could analyze a crash between the cars and calculate the effects of the powerups. A Car class could also implement Movable interface which will define how cars move.
Detection of the crash:
First thing that comes to mind is to analyze the area around each car and if another car is in this area (you know the dimension of the cars) than simply call the method which will calculate the collision. But this is probably a bad solution for a collision detection and should be done differently.
Last edited by baizba; 09-29-2010 at 07:44 PM.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•