Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Collision detection while jumping....

This topic is 6011 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m working on this side-scroller I have the graphics up the character is animated but when he jumps I am not quite sure on how to go about the collision detection. If he just jumped straight up I wouldnt have a problem I would simply wait till he starts to come down and test the tile under him for collision but then he could jump up through stuff but....sorry anyway he jumps up and over and tracking him on a tile by tile basis is kinda tricky with that or perhaps Im missing something....please help. Thanks in advance. If this post would be better somewhere else just direct me to it, no problem.

Share this post

Link to post
Share on other sites
To check which tile a character is in, follow these easy steps (wow, I could be a salesman!):

1. Define an "action point" for your sprite. For example, if your sprite is a person, say 32x128, then you might want to check for collisions at his feet, so your action point is (15,127). This is done before the game loads - you could store it with your imagery (you might need a different action point for each frame...)

2. Find out the "world" coordinates of the action point. To do this, add the player''s coordinates to the action point coordinates:
PLAYER(150,400) + ACTION_POINT(15,127) = WORLD_ACTION_POINT(165,527)

3. Check this value against your tile database. To do this, divide the x coordinate by the tile width, and the y coordinate by the tile height. This gives you two values which you can use to index into your array of tiles.

Now that you can easily find which tile a character is "in", you can check this against that tile''s flags. The tile flags might include:

IMPASSABLE - you can''t cross, no matter what.
JUMP_THROUGH - you can pass through when you are jumping up, but not when you are falling / walking
PASSABLE - you can walk through this
WATER? - you must swim here....
LAVA - you must die here


If you need more help, just ask. The moderators may move this thread to "Game Programming", so be warned =)

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!