Jump to content
  • Advertisement


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


Tilebased Side Scroller

This topic is 5645 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

My tile based game continues, but I''m still having trouble getting the object to world collision detection working; that is, keeping things from flying through walls or doing weird things when they hit corners. I don''t know what I''m doing wrong but I just can''t come up with a right way for it. This should be such a simple problem! My basic algorithm is: Calculate an object''s new position based on velocity and time elapsed since previous frame. Check if the object''s bounding box will overlap any wall tiles at that position. If so, check left/right above/below in front of/behind the bounding box based on our velocity vector and then move the object''s new position to be against any walls that are detected instead of inside them. Assign the object to the new location. This works fine for simple things, like crashing into flat walls or ceilings, but when the objects hit corners or hit at angles, things fall apart quickly. The code itself is very long and repetive so heres the basic layout of it in pseudocode:


  if(newposition.x+bbox.width is inside a wall tile)
    newposition.x=tile we collided with-bbox.width
else if(vx<0)
  if(newposition.x-bbox.width is inside a wall tile)
    newposition.x=tile we collided with+bbox.width

[ same structure for Y and Z axes ]

  tell the object to adjust its new position to match the adjusted location

It works OK until the objects start colliding with the world at angles or hit the corners of blocks. Is my algorithm sound and I should just look for implementation uh-ohs, or am I barking up the completely wrong tree? Further information upon request.

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!