Results 1 to 11 of 11
  1. #1
    Join Date
    Feb 2011
    Posts
    8
    Rep Power
    0

    Talking 2D collision handling between two different moving objects

    Hi,

    I'm making a 2d top-down space strategy game with a variety of space ships in Java. Up till now I've simply had collision detection between ships and weaponry, edges of the screen etc, but now I want to try and go a step up and cause ships to damage and rebound in the appropriate directions when colliding with one another. Actually detecting the collision is not too difficult but I'm struggling with what to do after that.

    How can I work out from the ships Velocities, Mass and angle of direction what the effect on them should be?

  2. #2
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    Presumably you already know the velocities of each object, else you can't paint them in the first place.

    Collision detection of moving objects (even if 1 is stationary) can be difficult if the velocities are high enough, because as you update positions, it's possible for a fast object to logically pass through another object that point-by-point collision detection will not discover. This can happen because positions are updated in discrete jumps to correspond with the frame rate. To handle that, you're in the realm of solving linear differential equations. For objects moving in straight lines at constant velocity, the collision check is pretty straightforward, but if you don't have a good math background, you're going to need to partner with someone who does, or use a physics engine, or limit velocities such that this scenario is impossible.

    At any rate, if two nondeforming point-objects collide, their new velocities are determined based on their respective velocities and masses according to the law of conservation of momentum, which states that m1*v1+m2*v2 = a constant, combined with Newton's 3rd law which states that the the sum of the forces each object experiences in each dimension will be 0. If your eyes haven't glazed over let me know.

  3. #3
    Join Date
    Feb 2011
    Posts
    8
    Rep Power
    0

    Default

    yeah... unfortunately I only understood about half of what you just said. :( I don't think the velocities should be so high that objects can pass through each other without recognising a collision, though I am working on changing the way I look at ship to ship collision detection as currently it waits till a ship has moved and then checks if it has moved into the same position as another ship, but I instead want to check the position it is going to move to BEFORE allowing the move, if that makes sense.

    I've also yet to assign masses to any of my ship types as I am still trying to understand everything. Could you perhaps explain a bit more?

    Thanks so far

  4. #4
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    Have you had a basic physics class, and do you have a good grasp of trig?

  5. #5
    Join Date
    Feb 2011
    Posts
    8
    Rep Power
    0

    Default

    I can handle the trig ok but I'v never done any physics, which is where I'm falling down

  6. #6
    I_S_Patil is offline Member
    Join Date
    Apr 2011
    Location
    Bengaluru
    Posts
    4
    Rep Power
    0

    Cool

    I can help u.. If u r ready to accept objects as Non-Elastic....
    i.e., U should assume that your space ships r not undergoing any deformation in
    their shape. If their shapes change.. Then law m1*v1=m2*v2 fails.
    Because the momentum of both ships is lost due absorption of energy in changing the shape of space ship.

  7. #7
    Join Date
    Feb 2011
    Posts
    8
    Rep Power
    0

    Default

    hmm well I'm fairly certain I want it to be non-elastic. The idea is that the ships will take some damage based on speed and weight, e.g. if a small ship goes flying into a larger one, the small ship might ricochet a lot and taken a lot of damage while the larger one is affected a lot less.

  8. #8
    I_S_Patil is offline Member
    Join Date
    Apr 2011
    Location
    Bengaluru
    Posts
    4
    Rep Power
    0

    Post

    I hope u still have idea of having Elastic collision...
    It will be difficult to analyse it precisely.. So u can adopt following method


    1. Assume elastic collision
    2. Find the final change in direction & velocity of space ships
    3. Since u want to assume damage to space ship, reduce the final velocity of
    both ships by some % ( Say 3-5 % ).
    * Do not change the direction of ships

    Still if u do not know to calculate change in velocity & direction of ships after collision as Non-Elastic,i well tell u how to do that

  9. #9
    Join Date
    Feb 2011
    Posts
    8
    Rep Power
    0

    Default

    I'm happy to still do elastic collision and just estimate some damage afterwards, but its working out the change in velocity and direction that I need the help with.

  10. #10
    I_S_Patil is offline Member
    Join Date
    Apr 2011
    Location
    Bengaluru
    Posts
    4
    Rep Power
    0

    Thumbs up Scanned copies of problem

    Sorry for taking such a long time..
    Though i completed these very early..
    I could not upload these because i was busy in my work.
    Attached Thumbnails Attached Thumbnails 2D collision handling between two different moving objects-1.jpg   2D collision handling between two different moving objects-2.jpg   2D collision handling between two different moving objects-3.jpg   2D collision handling between two different moving objects-4.jpg   2D collision handling between two different moving objects-5.jpg  


  11. #11
    I_S_Patil is offline Member
    Join Date
    Apr 2011
    Location
    Bengaluru
    Posts
    4
    Rep Power
    0

    Default Re: 2D collision handling between two different moving objects

    I see lot of views for this thread. Has any body observed my calculations. Give feed back.

Similar Threads

  1. code for moving objects at same time
    By Muhammad Assad in forum New To Java
    Replies: 13
    Last Post: 06-20-2010, 05:11 PM
  2. Problem in collision between objects
    By Chetans in forum Java Gaming
    Replies: 3
    Last Post: 03-15-2010, 11:24 PM
  3. Moving objects
    By rsjava24 in forum AWT / Swing
    Replies: 1
    Last Post: 02-26-2010, 10:47 AM
  4. Moving objects - setting different speed
    By Antigol in forum Java 2D
    Replies: 2
    Last Post: 08-14-2009, 01:14 AM
  5. examples of moving objects
    By fred in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06:06 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
  •