Mappy Collision Help

BlitzMax Forums/BlitzMax Beginners Area/Mappy Collision Help

technician(Posted 2006) [#1]
I had a few questions concerning Mappy collision. I'm working on a side-scrolling platformer, and have just switched over to using Mappy. I've adapted the collision code from the example, but I'm having issues on the corners of the objects. Sometimes the character will "slide" into the block, but if you jump, he'll pop out just fine. Otherwise, collision works fine.

I'm using a 64x64 pixel character sprite, and 32x32 blocks. I basically just check each of the four corners for collision (character.X+32, character.Y+32, etc.), with a check in the middle bottom (x,y+32) because the blocks are so small, you need that third check so you don't fall through while standing on top of a single block.

A downloadable demo of my prealpha is available at: http://myopia.c-reality.com/uploads/AmuckPreAlpha.zip and it highlights the problem I'm having.

Here's my collision function:

Function Collision()
	
	' Check collision on sides of the RUDY sprite
	
	' Left
	If Rudy.X < Rudy.OldX
		If map.MapCollision(Rudy.X-32, Rudy.Y-30) Or map.MapCollision(Rudy.X-30,Rudy.Y+30)
			Rudy.X = Rudy.Oldx 
		EndIf
	Else
		' Right
		If map.MapCollision(Rudy.X+32, Rudy.Y-30) Or map.MapCollision(Rudy.X+32,Rudy.Y+30)
			Rudy.X = Rudy.OldX
		EndIf
	End If
	
	' Check collision on the top and bottom of the RUDY sprite
	' TOP
	If map.MapCollision(Rudy.X-20, Rudy.Y-34) Or map.MapCollision(Rudy.X+20, Rudy.Y-34)
		Rudy.Jump = 0
	EndIf
	' BOTTOM
	If map.MapCollision(Rudy.X-25, Rudy.Y+34) Or map.MapCollision(Rudy.X+25,Rudy.Y+34) Or map.MapCollision(Rudy.X,Rudy.Y+34)
		Rudy.Y = Rudy.Oldy
		Rudy.yCol = 1
	Else
		Rudy.Y :+ Rudy.Gravity
		Rudy.yCol = 0
	EndIf
			
EndFunction


Thanks in advance for any help. I'm basically just looking to avoid the "slide in," so my collision is 100%.


SpaceCowboy(Posted 2006) [#2]
I don't know about Mappy specifically, but I was doing player-tile collision detection in a similar way and it was very glitchy.. but then i changed to something like this:

While ImagesCollide(playerbottom,player_x,player_y,player_frame,tilesprite,tile_x,tile_y,tile_frame)
     player_y:-1
Wend

While ImagesCollide(playertop,player_x,player_y,player_frame,tilesprite,tile_x,tile_y,tile_frame)
     player_y:+1
Wend

While ImagesCollide(playerleft,player_x,player_y,player_frame,tilesprite,tile_x,tile_y,tile_frame)
     player_x:+1
Wend

While ImagesCollide(playerright,player_x,player_y,player_frame,tilesprite,tile_x,tile_y,tile_frame)
     player_x:-1
Wend


..where playertop, playerbottom, playerleft and playerright are sprites - the same size as the player sprite - with just the top, bottom, left and right bit of the player sprite on each... if that makes sense.

splitting the player's collision mask into 4 parts and changing from "if" to "while" solved all the glitches and it now works perfectly, for any shape/size of tile, and for moving tiles/enemies etc...

so you could use the same method with the mappy collision commands instead of ImagesCollide() I guess.

if you do it this way you have to be careful and make sure the player will definately move off the tile though, or it'll get stuck in an infinite "while" loop :)

there might be better ways of doing it, i dunno.