Why does get_cellv() always gives me -1?

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

This is my code:

extends Node2D


func _process(delta):
    #NodeD2 = center of the viewport.

	if Input.is_action_just_pressed("ui_accept"):
		if $NodeD2.scale.y == 1:
			$NodeD2.scale.y = -1
		else:
			$NodeD2.scale.y = 1
	if Input.is_action_just_pressed("ui_cancel"):
		if $NodeD2.scale.x == 1:
			$NodeD2.scale.x = -1
		else:
			$NodeD2.scale.x = 1
	
	var cell = $NodeD2/TileMap.world_to_map($Player.get_position())
	var tile_id = $NodeD2/TileMap.get_cellv(cell)
	print(tile_id)
:bust_in_silhouette: Reply From: rakkarage

it is equal to INVALID_CELL and means that cell on that tilemap is empty

if you think it should not be empty:
try print(cell)to ensure it is reasonable or passing in a cell that you know is not empty?

print($NodeD2/TileMap.get_cellv(Vector(12, 12)))

Print(cell):
i.e (2, 24)
The tiles which the player can stuck when flipped only vertically:
(-1, 11), (15, 10) and (23, 11)
Yeah, definitely there’s a problem with the coordinates. Thanks!

Gonz4 L | 2020-09-20 21:05