A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Collision Detection Technique - Staying on the Ground?

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    1

    Collision Detection Technique - Staying on the Ground?

    Hey all,

    I apologize if there are previously existing threads on this - I wasn't even sure what to search for.

    I am working on a type of platformer style game, and wondering about the best approach for collision detection with the ground:

    Right now, my basic approach is to test if the character's position plus his downward velocity would put him below the height of the floor. If so, the next frame would be a collision, so I then put him at the height of the floor.

    My problem is that, with uneven floor heights and floating point errors in the positioning math, the character always ends up slightly above or slightly below the floor height, resulting a slight vertical shaking as he is constantly repositioned near floor height, but never exactly.

    Am I missing some basic approach that would avoid this problem?

  2. #2
    When you know are. Son of Bryce's Avatar
    Join Date
    Aug 2002
    Location
    Los Angeles
    Posts
    838
    I'm not sure what to tell you about your problem but you could definitely find some ideas or solutions if you search this games forum.

    Try searching for a combination of "collision", "platformer", "hittest", "gravity", "ground", etc. And you should be able to find something useful.

    You might be able to find something in the Knowledgebase thread stickied to the top of the forum. This Hit Test and Basic Collision thread might help.
    Last edited by Son of Bryce; 12-01-2010 at 10:43 AM.

  3. #3
    Custom User Title Incrue's Avatar
    Join Date
    Feb 2004
    Posts
    973
    If the floor is at 200, put him at 199.5

  4. #4
    Junior Member
    Join Date
    Dec 2010
    Posts
    4
    Quote Originally Posted by Incrue View Post
    If the floor is at 200, put him at 199.5

  5. #5
    Junior Member
    Join Date
    Dec 2010
    Posts
    4
    how to edit my post? lol

    incrue's suggestion is my game's solution too. it works great... you may also add into ur sprites a 1px solid black stroke, so you wont know where the ground begins or the character finishes.

  6. #6
    Custom User Title Incrue's Avatar
    Join Date
    Feb 2004
    Posts
    973
    I guess 199.8 will also be good enough
    What matter is, give it a margin of error

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