#How do I program a collision for a tileset?

16 messages · Page 1 of 1 (latest)

quick barn
#

I'm new to GMS2 and I'm trying to make a simple platformer rn. I drew a ground sprite and I tried programming my character to collide with it by typing move_and_collide(xsp,ysp,TileSet1)
but for some reason my character didn't collide with it and just kept moving through it.

abstract wind
#

you need to collide with the tilemap rather than the tileset. The tileset is your asset in the asset browser, the tilemap is your layer in the room where you drew the tiles

#

so you need to do layer_tilemap_get_id to get the tilemap ID, and then plug that in

quick barn
#

ah

abstract wind
#
move_and_collide(xsp,ysp,tile_collision)``` swap out Tiles_1 for whatever your tile layer is
quick barn
#

ok let me try that

#

ok this worked. Thank you so much

#

ok so I got a new problem. I'm now trying to code jumping and I'm trying to program my character to recognize when its standing on said tileset. I wrote the code `if place_meeting(x,y+1,"Tiles_1")
{
ysp=0
if keyboard_check(vk_up)
{
ysp=-2
}
}

var tile_collision = layer_tilemap_get_id("Tiles_1");
move_and_collide(xsp,ysp,tile_collision)`

#

but it causes the game to crash upon launching it

#

ok so I fixed it but now I have a new problem

#

my character won't move at all

#

`ysp+=0.1
xsp=0

if keyboard_check(vk_left)
{
xsp=-1
}

if keyboard_check(vk_right)
{
xsp=+1
}

if place_meeting(x,y+1,TileSet1)
{
ysp=0
if keyboard_check(vk_z)
{
ysp=-2
}
}

var tile_collision = layer_tilemap_get_id("Tiles_1");
move_and_collide(xsp,ysp,tile_collision)`

#

this is my current code for my character.

#

I could move my character just fine before I added the "if place_meeting" lines

abstract wind
#

like you can't move horizontally either? Or just vertically

#

vk_z is wrong for pressing the z key, for letter keys you need to use ord, like ord("Z") since there's no vk_ constants for the letters