A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: surface angles (yet another collision thread)

  1. #1
    Junior Senior
    Join Date
    Nov 2000
    Location
    sydney
    Posts
    565

    surface angles (yet another collision thread)

    I'm writing a top-down racing game, using point to shape collision to see if the car is on the track. Aside from the hitTest, it also needs to determine the angle of the collision. I know what angle the car is travelling of course, but was wondering if anyone had suggestions for determining the angle of a certain section of artwork, specifically the surface normal at the point of impact.

    the two methods I am considering are-

    1. create a large underlying structure of objects that are used for collision detection instead of the track graphic. each object holds a variable containing a predefined surface normal. this method would either mean lots of hit tests, or extremely complex 'normal objects' or both.

    2. after collision is detected, recurse back along the trajectory to find the exact point of collision. Then, perform a small circle of point to shape hit tests around that point, and derive an estimate of surface normal from the average angles of those which did not collide. ( example pic using 8 test points, in reality you'd use maybe 32: http://www.evilbastard.org/slight/hittestthing.gif )

    any thoughts on better methods or improvments on these two?

  2. #2
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    over at www.illogicz.com the dude has created a collision editor (ICE). this will generate a map that will allow you to determine the angle of the surface at any point. unfortunatly it's not available for use.
    i think you could achieve a similar (but not as good) result by taking an mc with a map of the playing area, solid areas are filled and moveable areas are transparent. then test every pixel using hittest(). you can use the resuting data to create a tilebase hitmap that contains the angle of the surface for each cell.
    Graphics Attract, Motion Engages, Gameplay Addicts
    XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

  3. #3
    Junior Senior
    Join Date
    Nov 2000
    Location
    sydney
    Posts
    565
    Whoa! Thanks Blink, that link made my day.
    I knew someone would post something cool if I came here and asked, but ICE is way beyond anything I'd expected. Can't wait till he releases it.

  4. #4
    Senior Member siriuss's Avatar
    Join Date
    Jan 2003
    Location
    lost in thought
    Posts
    154
    for my worms engine (which I haven't worked on for a while!) I am attempting to use a system where I work out the actual point of collision from the vector then produce two parallel vectors either side at a small distance (currently 1px but may try smaller) of that vector. I then determine the points that these two collide at, and create the normal from those points.

    However, the system is not perfected and actually very buggy at the moment, although more likely due to coding errors than the system logic!
    ...?...

  5. #5
    Junior Senior
    Join Date
    Nov 2000
    Location
    sydney
    Posts
    565
    That sounds like it might be pretty similar in effect to the second method, siriuss. Can I ask how you go about determining the exact point of collision on a vector? All I was planning on doing was stepping back along the vector, recursively halving the step distance and doing a hitTest until the step distance < 1px.

  6. #6
    Senior Member siriuss's Avatar
    Join Date
    Jan 2003
    Location
    lost in thought
    Posts
    154
    Maybe exact was too optimistic a word. I just trace back the vector (i px at a time I think) from the hit point until there is no hit, therefore providing a reasonable estimate of where the edge is. I then tranform that point onto the two parallel vectors, check for a hit then start testing in the vector direction accordingly (e.g if the "left" vector does not hit at the equivalent point I increment the position along the vector, if it does I decrement along the vector).

    At the moment I determine the normal from the left and right vector hit points.

    Once (and if) I crack this code and it works perfectly, I'll release it open source. At the moment tho it's a bit messy and buggy, and I've been too distracted with Halo to do much about it
    ...?...

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