]> Untitled Git - frog-ninja.git/blobdiff - player/input/PlayerCameraHandler.gd
Moved camera vector stuff into CameraHandler
[frog-ninja.git] / player / input / PlayerCameraHandler.gd
index ab2b8659d4d90ea39529d3b457998fc050970fe6..d6fbe9d246ffccddd4ac461e61e8079d3abe2840 100644 (file)
@@ -14,6 +14,7 @@ class_name PlayerCameraHandler
 
 
 @onready var spring: SpringArm3D = $SpringArm3D
 
 
 @onready var spring: SpringArm3D = $SpringArm3D
+@onready var camera: Camera3D = $SpringArm3D/Camera3D
 
 
 # Called when the node enters the scene tree for the first time.
 
 
 # Called when the node enters the scene tree for the first time.
@@ -46,3 +47,14 @@ func update(input: InputPacket, delta: float):
 
        # horizontal camera rotation
        rotation.y -= camera_input_direction.x * delta
 
        # horizontal camera rotation
        rotation.y -= camera_input_direction.x * delta
+
+
+# Get the XZ input direction based on player's input relative to the camera
+func get_xz_direction_relative_to_camera(d: Vector2) -> Vector2:
+       if camera:
+               var forward := camera.global_basis.z
+               var right := camera.global_basis.x
+               var dir3 := forward * d.y + right * d.x
+               return Vector2(dir3.x, dir3.z).normalized()
+       else:
+               return Vector2.ZERO