Ship mostly works #10

Merged
chrisbell merged 60 commits from feature/ship-syncing into develop 2024-12-29 04:35:51 +00:00
3 changed files with 53 additions and 25 deletions
Showing only changes of commit beae9284e7 - Show all commits

View File

@ -12,4 +12,4 @@ func interact():
elif parent_ship.ship_is_piloted:
player_reference.set_is_piloting(false)
parent_ship.remove_piloting_player()

View File

@ -31,6 +31,9 @@ func _ready():
NetworkManager.property_update_received.connect(_on_property_update_received)
player_detection_area.body_entered.connect(_on_player_entered)
player_detection_area.body_exited.connect(_on_player_exited)
func _process(delta: float):
if piloting_player and piloting_player.is_network_authority:
handle_input(delta)
@ -39,31 +42,47 @@ func _process(delta: float):
interpolate_position_and_rotation(delta)
func handle_input(delta: float):
var input_vector = Vector3.ZERO
var forward_input = 0.0
var turn_input = 0.0
var vertical_input = 0.0
if Input.is_action_pressed("move_forward"):
input_vector.z -= 1
if Input.is_action_pressed("move_backward"):
input_vector.z += 1
# Forward and backward movement
if Input.is_action_pressed("move_forwards"):
forward_input += 1
if Input.is_action_pressed("move_backwards"):
forward_input -= 1
# Left and right turning
if Input.is_action_pressed("move_left"):
input_vector.x -= 1
turn_input -= 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
turn_input += 1
if input_vector.length() > 0:
input_vector = input_vector.normalized() * move_speed
apply_force(input_vector)
# Up and down movement
if Input.is_action_pressed("jump"):
vertical_input += 1
if Input.is_action_pressed("crouch"):
vertical_input -= 1
# Rotation handling
var yaw = Input.get_action_strength("turn_right") - Input.get_action_strength("turn_left")
var pitch = Input.get_action_strength("turn_up") - Input.get_action_strength("turn_down")
# Apply torque for turning
if turn_input != 0:
var torque = Vector3.UP * turn_input * base_turn_speed
apply_torque(torque)
print("Torque:", torque)
if yaw != 0 or pitch != 0:
apply_torque(Vector3(pitch, yaw, 0) * base_turn_speed)
# Apply force for forward and backward movement
if forward_input != 0:
var forward_direction = -global_transform.basis.z.normalized()
var forward_force = forward_direction * forward_input * move_speed
apply_central_force(forward_force)
print("Forward Force:", forward_force)
# Apply force for vertical movement
if vertical_input != 0:
var vertical_force = Vector3.UP * vertical_input * base_lift_speed
apply_central_force(vertical_force)
print("Vertical Force:", vertical_force)
func sync_ship_state():
if global_position != previous_position:
@ -97,8 +116,19 @@ func set_piloting_player(player: Player):
else:
print("The ship is no longer piloted.")
func remove_piloting_player():
piloting_player = null
ship_is_piloted = false
print("The ship is no longer piloted.")
func _on_player_entered(body):
if body is Player and body.get_parent() != self:
body.call_deferred("reparent", self, true)
body.ship_entered(self)
print("Player entered the ship area.")
func _on_player_exited(body):
if body is Player and body.get_parent() != get_node("/root/DevLevel/"):
body.call_deferred("reparent", get_node("/root/DevLevel/"), true)
body.ship_exited()
print("Player exited the ship area.")

View File

@ -3,7 +3,7 @@
[ext_resource type="Script" path="res://assets/core/ships/test-ship/test_ship.gd" id="1_yql7r"]
[ext_resource type="PackedScene" uid="uid://dm31ddavxv5gt" path="res://assets/core/interactables/ship-helm/ship-helm.tscn" id="3_3wdac"]
[ext_resource type="PackedScene" uid="uid://f7xy5w0gmpwj" path="res://assets/core/ships/test-ship/airship_raft.glb" id="3_h6lyp"]
[ext_resource type="Material" uid="uid://ctemnr3tq0iu0" path="res://assets/core/ships/test-ship/new_standard_material_3d.tres" id="4_hhywo"]
[ext_resource type="Material" path="res://assets/core/ships/test-ship/new_standard_material_3d.tres" id="4_hhywo"]
[sub_resource type="BoxShape3D" id="BoxShape3D_kbheo"]
size = Vector3(12.0762, 9.20947, 45.9958)
@ -20,10 +20,8 @@ script = ExtResource("1_yql7r")
ship_area = NodePath("Area3D")
ship_helm = NodePath("ShipHelm")
[node name="ShipHelm" parent="." node_paths=PackedStringArray("parent_ship", "helm_lock_pos") instance=ExtResource("3_3wdac")]
[node name="ShipHelm" parent="." instance=ExtResource("3_3wdac")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1.47976, -10.9455)
parent_ship = NodePath("..")
helm_lock_pos = NodePath("HelmLockPos")
[node name="HelmLockPos" type="Marker3D" parent="ShipHelm"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.345567, 1)