Input Position does not line up with tilemap when zoomed or panned.

Godot Version

Godot_v4.6.1-stable_win64

Question

Hi Guys, im trying to make a 2d Isometric (Diamond Right) Pixelart Game. For that I need the player to place tiles inside a tilemap, which is working great so far. However i just tried to implement camera zooming and panning, and now the positions are all messed up... :(

I have a input function, which returns the klicked/tapped position to the input position handler function. >>>func _handle_input_position(screen_pos: Vector2):
var world_pos = $Camera2D.get_global_transform().affine_inverse() * screen_pos
var tile_pos = tilemap.local_to_map(world_pos)

Well, thats what ChatGPT told me to write…., however this (and what i had before) only works, when the camera hasn´t been moved or zoomed.