From cbd9db488fe57d341fd5e6aa3a667d853f4299dc Mon Sep 17 00:00:00 2001 From: Josh Creek <8179928+jcreek@users.noreply.github.com> Date: Wed, 21 Feb 2024 18:09:13 +0000 Subject: [PATCH] feat(#2): Add the ability to move the vehicle up, down, left, right, forwards, backwards using the keyboard --- Game/scripts/Vehicle.gd | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Game/scripts/Vehicle.gd diff --git a/Game/scripts/Vehicle.gd b/Game/scripts/Vehicle.gd new file mode 100644 index 0000000..33fd102 --- /dev/null +++ b/Game/scripts/Vehicle.gd @@ -0,0 +1,31 @@ +extends RigidBody3D + +var speed = 10.0 # Adjust the speed as necessary + +func _integrate_forces(state): + var input_vector = Vector3.ZERO + if Input.is_action_pressed("move_forward"): + input_vector.z -= 1 + 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 + + input_vector = input_vector.normalized() * speed + state.linear_velocity = input_vector + + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass