+1 vote

I have a 2D kinematic body named "spider" and a TileMap in the same scene. I want the player to 'die' when on a certain tile.

The code I tried for this is mostly attempts at using worldtomap and get_cellv, and whenever it runs I just get -1 or (0, 0), so I'm left confused. I'm still quite new to Godot and can't get it working at all, so any help would be appreciated.

code on a 2D node:
var posx = player.position.x
var posy = player.position.y
print(map.worldtomap(Vector2(posx, posy))) -- output: (0, 0)

asked Jul 11 in Projects by Ledwan (15 points)

1 Answer

+1 vote

im not sure how to do what you want exactly how you think you want to do it, but you can easily think of a workaround.

example: seperate the deadly tileset with the non-deadly tileset (in the same scene). this gives flexibility when your checking for collision. say, name the deadly tileset is "die" and the safe one "normal". then, when you check for collision, get the colliders name and if the name of the collider is "die",call your playerdeath function. this is a relatively simple workaround, but it should work more or less.

answered Jul 11 by dustin (416 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.