get_global_rect() with transformations of Camera2D

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


I have a Control Node where I want to check if a mouse click is inside my global_rect:

if event is InputEventMouseButton and get_global_rect().has_point(event.position):
    # do stuff

This works fine, but when I add an Camera2D with zoom and offset, I still have to click where the nodes rect would be without the camera. So how can I apply the camera transformation to my code?

Thanks for your help!

:bust_in_silhouette: Reply From: TobiLa

I solved it, for those coming later:
I changed event.position to

var eventPosition = get_viewport().canvas_transform.affine_inverse().xform(event.position)