Results 1 to 2 of 2
Thread: Solving Collisions in a car game
- 09-29-2010, 06:27 AM #1Member
- Join Date
- Aug 2010
- Rep Power
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 06:38 AM.
- 09-29-2010, 03:13 PM #2Member
- Join Date
- Sep 2010
- Rep Power
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 08:44 PM.
- By Atriamax in forum New To JavaReplies: 9Last Post: 08-28-2010, 06:55 PM
- By Luff in forum AWT / SwingReplies: 7Last Post: 06-23-2010, 01:30 PM
- By bdario1 in forum New To JavaReplies: 4Last Post: 04-14-2010, 01:02 AM
- By Felicia in forum New To JavaReplies: 5Last Post: 03-04-2010, 09:40 PM
- By highschool in forum New To JavaReplies: 6Last Post: 02-25-2010, 04:36 PM