mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-07-12 18:43:49 +00:00
fix(*): Change direction relative to player not the world
This commit is contained in:
+24
-13
@@ -2,17 +2,28 @@ extends 'res://scripts/Vehicle.gd'
|
|||||||
|
|
||||||
func get_input_vector() -> Vector3:
|
func get_input_vector() -> Vector3:
|
||||||
var input_vector = Vector3.ZERO
|
var input_vector = Vector3.ZERO
|
||||||
if Input.is_action_pressed("move_forward"):
|
var camera_path = "/root/MatchNode3D/Players/GridContainer/SubViewportContainer/SubViewport/Player1/Camera3D"
|
||||||
input_vector.z -= 1
|
var camera = get_node(camera_path)
|
||||||
if Input.is_action_pressed("move_backward"):
|
|
||||||
input_vector.z += 1
|
|
||||||
if Input.is_action_pressed("move_left"):
|
|
||||||
input_vector.x -= 1
|
|
||||||
if Input.is_action_pressed("move_right"):
|
|
||||||
input_vector.x += 1
|
|
||||||
if Input.is_action_pressed("move_up"):
|
|
||||||
input_vector.y += 1
|
|
||||||
if Input.is_action_pressed("move_down"):
|
|
||||||
input_vector.y -= 1
|
|
||||||
|
|
||||||
return input_vector
|
if camera:
|
||||||
|
var camera_transform = camera.global_transform
|
||||||
|
var forward_direction = -camera_transform.basis.z
|
||||||
|
var right_direction = camera_transform.basis.x
|
||||||
|
|
||||||
|
if Input.is_action_pressed("move_forward"):
|
||||||
|
input_vector += forward_direction
|
||||||
|
if Input.is_action_pressed("move_backward"):
|
||||||
|
input_vector -= forward_direction
|
||||||
|
if Input.is_action_pressed("move_left"):
|
||||||
|
input_vector -= right_direction
|
||||||
|
if Input.is_action_pressed("move_right"):
|
||||||
|
input_vector += right_direction
|
||||||
|
if Input.is_action_pressed("move_up"):
|
||||||
|
input_vector.y += 1
|
||||||
|
if Input.is_action_pressed("move_down"):
|
||||||
|
input_vector.y -= 1
|
||||||
|
|
||||||
|
return input_vector.normalized()
|
||||||
|
else:
|
||||||
|
print("Camera not found")
|
||||||
|
return Vector3.ZERO
|
||||||
|
|||||||
Reference in New Issue
Block a user