Tile based platform game collision :(

BlitzPlus Forums/BlitzPlus Programming/Tile based platform game collision :(

Binary_Moon(Posted 2003) [#1]
I need some help with some tile based platform game collision. I'm actually converting some DB platform game code that can be found here

http://underwaredesign.com/prod_detail.php?rnd=2069544173&id=20

Go down to the collision and intersection section and get the top one.

My code is here

http://www.binarymoon.co.uk/preview/platform_test.zip

The code works fine if you only move in one direction. As soon as you get into a collision on a diagonal it messes up.

I can't see what i have done wrong... any help would be appreciated


Zster(Posted 2003) [#2]
Ok this fixes it
;---------------
;right collision
;---------------
If vx>0
	;If vy=0
	
		If Abs(osx2-1)<=xpos1
			dx#=xpos1-(odx2)
			odx1=Abs(odx1+dx)
			odx2=Abs(odx2+dx)
			
			resolve=False
			collisionRight=True
		EndIf
		
	ElseIf osy1<(ypos2-1)
	
		If Abs(osx2-1)<=xpos1
			dx#=xpos1-(osx2)
			odx1=Abs(odx1+dx)
			odx2=Abs(odx2+dx)
			
			resolve=False
			collisionRight=True
		EndIf
		
	;EndIf
EndIf



I've commented out the "If vy=0" and related "EndIf" as it means it only does a right side detection if you're not moving down. You always want to be doing a right side detection if vx>0. Remember to remove it from the left side code as well. (the code is in tile map collision). PS your Rocket Racer game looks awesome.


Zster(Posted 2003) [#3]
I noticed something else. Right side works perfectly now but left side will not work if your hitting something above or below. Can't figure this one out for the moment


Binary_Moon(Posted 2003) [#4]
Zster - Thanks for trying. I showed this to the author of the original code (which uses the code you commented out) and he reckons the reason it doesn't work is because it is reading the tiles in the wrong order. It needs to change the direction of the xloop and yloop variables in order to find the first tile you collide with.

Blitz doesn't allow variable step sizes which is why this doesn't work. I have tried using while loops instead and it still isn't having it. I'm determined to get it to do something though.

"PS your Rocket Racer game looks awesome" - cheers :)