Shoot in 2D, look_at() function

There are two distinct problems you need to solve. First, the global mouse coordinates are relative to the CanvasLayer origin. This is a position that is not where your object is, so you need to take the difference. For that it’s actually easier to use local coordinates.

var pos = get_local_mouse_position() - position

The other part is look_at() assumes your sprite starts looking to the right (aka east, aka positive x). If your sprite is looking up, you need to subtract 90 degrees (aka PI/2, aka TAU/4 radians) to correct the rotation.
Finally, you don’t want to do this in the physics process specially since you’re extending Node2D, not a physics node.

1 Like