extends RigidBody3D

@onready var grab_fix_point: Node3D = $"../../Character/Head/GrabFixPoint"

var grabbed: bool = false

var rotate_todo:float = 0

func _input(event: InputEvent) -> void:
	if event.is_action_pressed("wheel_up"):
		rotate_todo += 30
	if event.is_action_pressed("wheel_down"):
		rotate_todo -= 30
	
	if event.is_action_pressed("grab"):
		grabbed = !grabbed
		print("grab: %s"%grabbed)
		if grabbed:
			grab_fix_point.global_position = global_position
			freeze = true
		else:
			freeze = false
			
			
func self_rotate(amount_deg:float):
	var axis = Plane(Vector3.UP).project(-grab_fix_point.global_transform.basis.z).normalized()
	var amount_rad =deg_to_rad(amount_deg)
	print("Rotating around %s by %s deg or %s rad"%[axis,amount_deg,amount_rad])
	rotate(axis,amount_rad)
	print("New rotation: %s"%rotation_degrees)
	
	
func _physics_process(_delta: float) -> void:

	
	if grabbed:	
		self_rotate(rotate_todo)
		rotate_todo = 0
		#var axis = Plane(Vector3.UP).project(-grab_fix_point.global_transform.basis.z).normalized()
		#rotate(axis,_delta*3.14)
		global_position = grab_fix_point.global_position
