Godot Version
4.1.1
Question
Error:
I am attempting to let the player place a tile from a “Place-ables” tilemap, but when the zoom of my camera is anything but 1, the placing freaks out, placing tiles much further away than they should be placed. This is due to global position to tilemap relative position transformation.
How are some ways I could fix this?
Code:
extends TileMap
var tilemap_position
var tilemap
var groundlayer = 0
var source_id = 1
func _ready():
pass
func _process(_delta):
pass
func _input(event):
# Mouse in viewport coordinates.
tilemap = $"."
groundlayer = 0
source_id = 1
if Input.is_action_just_pressed("place"):
print("Mouse Click at: ", event.position)
tilemap_position = tilemap.local_to_map(Vector2i(event.position.x -192, event.position.y +120))
print(tilemap_position)
set_cell(0, tilemap_position, source_id, Vector2i(0,0))
$"../Resources".set_cell(0, tilemap_position, source_id, Vector2i(0,0))
Thanks!