How to calculate angle between two vectors

Godot 4

Hi! I need to calculate angle beetwen two wektors. One points toward right side from the center, and the other one follows the mouse. I know I can use a dot product but I am not shure how to do it. I need some advice how to implement it in my code.

Right now my code returns strange values unfortunetly…

func _angle():
	var mouse = get_global_mouse_position()
	var direction = (mouse - debug_center.position)
	var angle = 90 - rad_to_deg(direction.angle())
	print(angle)

You could just use the Vector2 class’s angle_to function ?

If you second vector is always (1, 0) (normalized) then you can use Vector2.angle: Vector2 — Godot Engine (stable) documentation in English.

var angle = rad_to_deg(direction.angle())