How can i get the tile id and position that is colliding with my player?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By javrocks

extends KinematicBody2D

var cell
var tile_id

func _ready():
pass

func _physics_process(delta):

if (collision.collider.name == “TileMap”):
cell = tile_map.world_to_map(position)
cell -= collision.normal
tile_id = collision.collider.get_cellv(cell)

print(cell)

#After that this error appears Invalid get index ‘collider’ (on base: ‘Nil’).

It gives me the same error for:

if (collision.collider.name == “TileMap”):

what should i change it to

javrocks | 2021-04-04 14:46

:bust_in_silhouette: Reply From: exuin

You should call world_to_map() on the TileMap, not on the collider.