dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Bouncing away from object on collision?

Hybrid View

  1. #1
    Junior Member
    Join Date
    Mar 2007
    Posts
    3

    Bouncing away from object on collision?

    Hi there guys,

    I've spent the last 12 hrs on this issue and its starting to tick me off. I have a Space craft that is moved via the standard sine/cosine formula (I.e. xSpeed = Math.sin(craft._rotation*Math.Pi/180) etc..), I also have a group of Asteroids floating around in space. Basically, I need the ship to get bounced away from the Asteroids if they collide with each other.

    E.g If the Asteroid's movement angle is 45 degrees and the craft's movement angle is 225 degrees, if they collide, I'd need the ship to be blasted back at an angle of 45 degrees. With me? I hope so :P

    Thanks for any help
    Hosma

  2. #2
    Knows where you live
    Join Date
    Oct 2004
    Posts
    944
    You are probbaly looking for "billiard ball" collisions. I suggest you just try to fake it as much as possible, because the math behind realistic circle to circle collisions is really complex.

    Just by skimming, this apears to be close to what you need:
    http://archive.ncsa.uiuc.edu/Classes...send/math.html

    There is a chapter on billiard ball collisions in Flash Game Design Demistified.
    Part of it is on google books (the page you are looking for is 136):
    http://www.google.ca/books?vid=ISBN0...#PRA3-PA136,M1
    But the entire chapter is not included so aside from an image and a table of contence you get nothing that will help you.

    To fake it, I would personally just use a verlet integration for the moving objects, and set up a 100% strength spring to push the ship and asteroid apart when they get close. Its still somewhat complex, but the math is manageable.
    The greatest pleasure in life is doing what people say you cannot do.
    - Walter Bagehot
    The height of cleverness is to be able to conceal it.
    - Francois de La Rochefoucauld

  3. #3
    Junior Member
    Join Date
    Mar 2007
    Posts
    3
    Yes its Billiard Ball collisions that I'm after, I knew the name was something like that. :P

    When you say complex, do you mean to the level that its actually hard to read? When I was trying to get it to work, I came up with the idea of just setting the crafts velocity based on whether it had its back to the asteroid or not. The fomula that I came up with needed a full 360 degrees angle variable (not flashes _rotation as that only has values up to 180, then goes into negatives) sop I wrote a function that converted the _rotation value to a true angle.
    The result of this formula was that if the ship was facing the asteroid when it collided (a threshhold of 180 degrees was used), it would bounce back like it was supposed to, however if the ship had its back to the rock, it would be sucked through the asteroid and sent flying backwards. :P

    I eventually figured out the reason for this was because I had forgotten that I was setting the x and y speed values for the craft (which are of course, negative inclusive variables), and not one speed value that only included positive numbers.

    Anyways, a friend has that book I think so I'll refer to it sometime soon.
    Thanks for your help

  4. #4
    Knows where you live
    Join Date
    Oct 2004
    Posts
    944
    Well the book essentially has the same formulas and diagrams as the first link in my previous post, its just a little more readable. If you can understand it (or just use it) you should be able to have realistic collisions.
    The greatest pleasure in life is doing what people say you cannot do.
    - Walter Bagehot
    The height of cleverness is to be able to conceal it.
    - Francois de La Rochefoucauld

  5. #5
    Junior Member
    Join Date
    Mar 2007
    Posts
    3
    Sorry I've taken so long to write back, I've been busy with game development. I have since read the chapters in the book and have successfully transfered the functions over for use in my game! I have to say, those collisions are more realistic then anything I could have hoped to achieve on my own. :P

    Thank you for your help!
    Hosma

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center