#### Archived

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.

## 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:


collided=false

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

[ same structure for Y and Z axes ]

if(collided)
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.

1. 1
2. 2
3. 3
Rutin
18
4. 4
5. 5

• 13
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
632926
• Total Posts
3009239
• ### Who's Online (See full list)

There are no registered users currently online

×