Untracked Files
This commit is contained in:
26
Scripts/Components/facing_direction_component.gd
Normal file
26
Scripts/Components/facing_direction_component.gd
Normal file
@@ -0,0 +1,26 @@
|
||||
extends Node
|
||||
class_name FacingDirectionComponent
|
||||
|
||||
signal DirectionChanged
|
||||
|
||||
@export var current_direction: Enums.Directions = Enums.Directions.DOWN
|
||||
|
||||
# Public Methods
|
||||
func GetCurrentDirection() -> Enums.Directions:
|
||||
return current_direction
|
||||
|
||||
|
||||
func ChangeDirectionUsingMovementVector(movement_vector: Vector2) -> void:
|
||||
var new_direction := _get_direction_from_mov_vec(movement_vector)
|
||||
if current_direction != new_direction:
|
||||
current_direction = new_direction
|
||||
DirectionChanged.emit()
|
||||
|
||||
|
||||
# Private Methods
|
||||
func _get_direction_from_mov_vec(mov_vec: Vector2) -> Enums.Directions:
|
||||
if mov_vec.x < 0: return Enums.Directions.LEFT
|
||||
if mov_vec.x > 0: return Enums.Directions.RIGHT
|
||||
if mov_vec.y < 0: return Enums.Directions.UP
|
||||
if mov_vec.y > 0: return Enums.Directions.DOWN
|
||||
return Enums.Directions.DOWN
|
||||
1
Scripts/Components/facing_direction_component.gd.uid
Normal file
1
Scripts/Components/facing_direction_component.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b0l02v61if6k8
|
||||
Reference in New Issue
Block a user