Add SpinComponent to handle rotation of a Node2D with adjustable speed and direction

This commit is contained in:
2025-05-25 03:48:01 +02:00
parent bb96553026
commit 60779f5b51
3 changed files with 49 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
class_name SpinComponent
extends Node2D
@export var root: Node2D
@export var speed: float = 8.0
@export var rotation_direction: Vector2 = Vector2.RIGHT
func _process(delta: float) -> void:
spin(delta)
func spin(delta: float) -> void:
if not root:
return
var rotation_speed: float = speed * rotation_direction.x
root.rotation += rotation_speed * delta