A Flash Developer Resource Site

Thread: Collision Detection Technique - Staying on the Ground?

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. 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.

3. If the floor is at 200, put him at 199.5

4. Originally Posted by Incrue
If the floor is at 200, put him at 199.5

5. 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. 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
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap

Click Here to Expand Forum to Full Width