GLBasic forum

Main forum => GLBasic - en => Topic started by: sionco on 2010-Feb-23

Title: platform collision (floating above or sinking down problem)
Post by: sionco on 2010-Feb-23
Hi this is my first post,
I'm having trouble with a platform game I've started,
Basically, I'm checking my players x and y positions against the tile one tile down in the tilemap, it works, he stands on any tile that is greater than 0, but as you can see from my pictures he is never actually directly aligned to the top of the tile, sometimes he is trouser deep sometimes even neck deep.

I'm not sure how to correct this, I've seen an example in another basic of using mod to position the player correctly. but I didn't really understand it

(http://picpaste.com/pics/prob1.1266938309.png)
http://picpaste.com/prob1.png (http://picpaste.com/prob1.png)
(http://picpaste.com/pics/prob2.1266938325.png)
http://picpaste.com/prob2.png (http://picpaste.com/prob2.png)

Code (glbasic) Select

LOCAL x1,y1
x1 = (playerX-offsetX)/tilesize //Player X pos - screen offset (for scrolling screen) / size of  tiles (32)
y1 = (playerY-offsetY)/tilesize+1

IF tilemap[x1][y1] > 0   //a 0 in the tile map means their isn't a tile
falling = 0        //player isn't falling
ELSE
falling = 1
playerY = playerY + gravity +playerYspd //move player downwads.
ENDIF
Title: Re: platform collision (floating above or sinking down problem)
Post by: bigsofty on 2010-Feb-23
Why not just make him have the same Y coord as the tile he is standing on, minus his height of course? As long as he not jumping or falling.
Title: Re: platform collision (floating above or sinking down problem)
Post by: sionco on 2010-Feb-23
Thanks it works,  :S :S

In the words of Homer 'Do'h'
I can't believe it's so obvious, what a great first post by me!
Title: Re: platform collision (floating above or sinking down problem)
Post by: bigsofty on 2010-Feb-23
No problem  :good: