Camera Zoom Breaks User Interaction with Tilesets

Godot Version

4.1.1

Question

Hi! In the city-builder I’m making, users can directly interact with the tilesets to place buildings, but when I make the camera zoom anything but 1, it affects the offset of the tile placement, and scale as well.

Here is my 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 -64, event.position.y +40))
		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 for the help!

It seems that whenever I zoom the camera by a factor of 2, clicking inside one tile allows the user to place houses in four different tiles far away, depending on the area in the tile where the click happens. Same for a zoom factor of 3: 9 houses can be placed.