Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2010
    Rep Power

    Default 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. #2
    baizba is offline Member
    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 07:44 PM.

Similar Threads

  1. Inelastic circle collisions
    By Atriamax in forum New To Java
    Replies: 9
    Last Post: 08-28-2010, 05:55 PM
  2. Check The Collisions
    By Luff in forum AWT / Swing
    Replies: 7
    Last Post: 06-23-2010, 12:30 PM
  3. Solving a Maze
    By bdario1 in forum New To Java
    Replies: 4
    Last Post: 04-14-2010, 12:02 AM
  4. I need help solving this problem.
    By Felicia in forum New To Java
    Replies: 5
    Last Post: 03-04-2010, 09:40 PM
  5. 4x4 2D array card game,need solving
    By highschool in forum New To Java
    Replies: 6
    Last Post: 02-25-2010, 04:36 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