Add SpinComponent to handle rotation of a Node2D with adjustable speed and direction
This commit is contained in:
18
scripts/components/spin_component.gd
Normal file
18
scripts/components/spin_component.gd
Normal 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
|
Reference in New Issue
Block a user