Discord
Login
Community
DARK THEME

Get Tile under Player

So this is my script

player = object end

tileSize = 16

init = function() player.y = 0 player.x = 0

player.vy = 3 player.vx = 3 end

update = function() // walking

if keyboard.A then player.x -= player.vx end if keyboard.D then player.x += player.vx end

// jumping

if keyboard.SPACE and player.y == 0 then player.vy = 4.5 end

player.vy = player.vy - 0.3 player.y = max(0,player.y+player.vy)

// ----- Physics -----

tileX = floor(player.x / tileSize) tileY = floor(player.y / tileSize)

tile = maps["foreground"].get(tileX, tileY)

print(tile)

end

draw = function() screen.clear(234567)

//screen.drawMap( "background", 0, 0, 356, 200 ) screen.drawMap( "foreground", 0, 0, 356, 200 )

screen.drawSprite("player/player_idle",player.x,player.y-35,40) end

I try to get the tile under the player to make physiks but the script gives completly random tiles that aren't under the player btw blocks have the pixel size 16x16 and the player pixel size is 33x33 can someone please help me.

i am having the same problem

Just take your sprite code then put it above the map code

Before: //screen.drawMap( "background", 0, 0, 356, 200 ) screen.drawMap( "foreground", 0, 0, 356, 200 )

screen.drawSprite("player/player_idle",player.x,player.y-35,40) end

After: screen.drawSprite("player/player_idle",player.x,player.y-35,40)

//screen.drawMap( "background", 0, 0, 356, 200 ) screen.drawMap( "foreground", 0, 0, 356, 200 ) end

Okay thanks it worked

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community