### Author Topic: platform collision (floating above or sinking down problem)  (Read 1347 times)

#### sionco

• Guest
##### platform collision (floating above or sinking down problem)
« 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/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&#39;t a tile
falling = 0        //player isn&#39;t falling
ELSE
falling = 1
playerY = playerY + gravity +playerYspd  //move player downwads.
ENDIF

#### bigsofty

• Community Developer
• Prof. Inline
• Posts: 2640
##### Re: platform collision (floating above or sinking down problem)
« Reply #1 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.
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

• Guest
##### Re: platform collision (floating above or sinking down problem)
« Reply #2 on: 2010-Feb-23 »
Thanks it works,

In the words of Homer 'Do'h'
I can't believe it's so obvious, what a great first post by me!

#### bigsofty

• Community Developer
• Prof. Inline
• Posts: 2640
##### Re: platform collision (floating above or sinking down problem)
« Reply #3 on: 2010-Feb-23 »
No problem
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)