feat(*): Add basic 2 player splitscreen

This commit is contained in:
Josh Creek
2024-03-21 20:12:53 +00:00
parent 5b686554c0
commit b7d52b7509
5 changed files with 120 additions and 21 deletions
+13 -15
View File
@@ -1,26 +1,24 @@
extends RigidBody3D
var speed = 10.0 # Adjust the speed as necessary
# Speed variable can be adjusted by subclasses
var speed = 10.0
func _integrate_forces(state):
# TODO - change these so they are relative to the vehicle, not the world
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 represents the movement input relative to the vehicle
var input_vector = get_input_vector()
# Scale the input_vector by speed
input_vector = input_vector.normalized() * speed
# Set the linear velocity based on the input
state.linear_velocity = input_vector
# Get the input vector from subclasses
func get_input_vector() -> Vector3:
var input_vector = Vector3.ZERO
# Subclasses will implement this function to provide their input mappings
return input_vector
# Called when the node enters the scene tree for the first time.
func _ready():
+18
View File
@@ -0,0 +1,18 @@
extends 'res://scripts/Vehicle.gd'
func get_input_vector() -> Vector3:
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
return input_vector
+18
View File
@@ -0,0 +1,18 @@
extends 'res://scripts/Vehicle.gd'
func get_input_vector() -> Vector3:
var input_vector = Vector3.ZERO
if Input.is_action_pressed("move_forward2"):
input_vector.z -= 1
if Input.is_action_pressed("move_backward2"):
input_vector.z += 1
if Input.is_action_pressed("move_left2"):
input_vector.x -= 1
if Input.is_action_pressed("move_right2"):
input_vector.x += 1
if Input.is_action_pressed("move_up2"):
input_vector.y += 1
if Input.is_action_pressed("move_down2"):
input_vector.y -= 1
return input_vector