platform collision (floating above or sinking down problem)

Previous topic - Next topic

sionco

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/prob1.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

bigsofty

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.
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

sionco

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!

bigsofty

Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)