Walking on slopes
BlitzMax Forums/BlitzMax Beginners Area/Walking on slopes
| ||
Hi, time for yet another question. Working on a tilemap engine and I want to add slopes. I'm having some problems when the player walks on them: Sometimes he cannot climb from one slope up to another (But he can go back to where he came from), and he can also fall between sloped tiles if one of the sloped tiles doesn't have a solid tile under it. Here is the collision code I have for the moment. It's called after applying gravity and when the player moves left/right Method check_collision() Local my:Int = y / Tsize ' Where in the map is the player? Local mx:Int = x / Tsize ' Check for a collision on layer 0 Local coll:Int = map_get_collision( mx,my,0 ) Select coll Case COLL_BOX y = oldy ' Cannot walk here at all. reset movement x = oldx Return True Case COLL_USLOPE ' Walking on a up / slope Local slope_y:Int = (x Mod Tsize) + 1 Local pos:Int = (my*Tsize)+Tsize-slope_y-1 If y > pos Then y = pos Return True Case COLL_DSLOPE ' Walking on a down \ slope Local slope_y:Int = (x Mod Tsize) + 1 Local pos:Int = (my*Tsize)+slope_y-1 If y > pos Then y = pos Return True EndSelect Return False ' No collision at all EndMethod x and y are floats and is not limited to anything. Therefore I use things like ( x Mod Tsize ) to get the offset in the current tile. Is this right? What else am I doing wrong? Anyone got any nice codesnippets showing how to walk on slopes with less bugs? Thankfull for any help. |