![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Gonz4 L |
And how to check if the tile is free when the tilemap is flipped (in my game when you press certain buttons, the tilemap is flipped horizontal or vertically but the character and maybe enemies and objects, that makes the character sometimes be stuck) and, if not, move the character (its collision shape) to the nearest free space (being the priorities up and down (depending on the position of the center (if in the middle of the tile, then up) ) and left or right if there’s no space in the previous directions) ? I tried to do it, but always gives me -1.
here’s 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(get_global_position())
var tile_id = $NodeD2/TileMap.get_cellv(cell)
print(tile_id)