Creating A Physics Based Spinning Wheel

I’m trying to create a 2d wheel where you spin it with your mouse to give it a velocity that it keeps. My current thought is using a rigid body where the change in rotations would become it’s angular velocity. The issue is, when calculating the rotation using atan2, there’s the seam where 2PI becomes 0 which messes with the calculation causing it to not spin at all.
Here’s the code:

extends RigidBody2D

var is_held : bool = false
var pre_click_rotation : float

@onready var previous_mouse_position : Vector2 = get_global_mouse_position()


func _process(delta: float) -> void:
	if is_held:
		var mouse_rotation = atan2(get_global_mouse_position().y, get_global_mouse_position().x) + (PI/2)
		var previous_rotation = atan2(previous_mouse_position.y, previous_mouse_position.x) + (PI/2)
		rotation += mouse_rotation - previous_rotation
	previous_mouse_position = get_global_mouse_position()

func _on_button_button_down() -> void:
	is_held = true
	pre_click_rotation = rotation


func _on_button_button_up() -> void:
	is_held = false
	var mouse_rotation = atan2(get_global_mouse_position().y, get_global_mouse_position().x) + (PI/2)
	var previous_rotation = atan2(previous_mouse_position.y, previous_mouse_position.x) + (PI/2)
	angular_velocity += (mouse_rotation - previous_rotation) * 2 

Don’t calculate rotation for each mouse vector. Instead, use Vector2::angle_to() to immediatelly get the rotation between two mouse vectors.

What’s the meaning of Vector2::angle_to()? I’ve never seen that double colon annotation before

It means that angle_to() function belongs to Vector2 class/namespace.

When using

		var mouse_rotation = global_position.angle_to(get_global_mouse_position())
		var previous_rotation = global_position.angle_to(previous_mouse_position)

I get a binary 0, or Pi. The global_position is at (0, 0)

You want the angle from one mouse vector to the other, the same thing you were previously trying to calculate using atans, not the angles between node position and mouse position, that doesn’t make much sense.