New ship new me
This commit is contained in:
parent
904141e541
commit
beae9284e7
@ -31,6 +31,9 @@ func _ready():
|
|||||||
|
|
||||||
NetworkManager.property_update_received.connect(_on_property_update_received)
|
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):
|
func _process(delta: float):
|
||||||
if piloting_player and piloting_player.is_network_authority:
|
if piloting_player and piloting_player.is_network_authority:
|
||||||
handle_input(delta)
|
handle_input(delta)
|
||||||
@ -39,31 +42,47 @@ func _process(delta: float):
|
|||||||
interpolate_position_and_rotation(delta)
|
interpolate_position_and_rotation(delta)
|
||||||
|
|
||||||
func handle_input(delta: float):
|
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"):
|
# Forward and backward movement
|
||||||
input_vector.z -= 1
|
if Input.is_action_pressed("move_forwards"):
|
||||||
if Input.is_action_pressed("move_backward"):
|
forward_input += 1
|
||||||
input_vector.z += 1
|
if Input.is_action_pressed("move_backwards"):
|
||||||
|
forward_input -= 1
|
||||||
|
|
||||||
|
# Left and right turning
|
||||||
if Input.is_action_pressed("move_left"):
|
if Input.is_action_pressed("move_left"):
|
||||||
input_vector.x -= 1
|
turn_input -= 1
|
||||||
if Input.is_action_pressed("move_right"):
|
if Input.is_action_pressed("move_right"):
|
||||||
input_vector.x += 1
|
turn_input += 1
|
||||||
if Input.is_action_pressed("move_up"):
|
|
||||||
input_vector.y += 1
|
|
||||||
if Input.is_action_pressed("move_down"):
|
|
||||||
input_vector.y -= 1
|
|
||||||
|
|
||||||
if input_vector.length() > 0:
|
# Up and down movement
|
||||||
input_vector = input_vector.normalized() * move_speed
|
if Input.is_action_pressed("jump"):
|
||||||
apply_force(input_vector)
|
vertical_input += 1
|
||||||
|
if Input.is_action_pressed("crouch"):
|
||||||
|
vertical_input -= 1
|
||||||
|
|
||||||
# Rotation handling
|
# Apply torque for turning
|
||||||
var yaw = Input.get_action_strength("turn_right") - Input.get_action_strength("turn_left")
|
if turn_input != 0:
|
||||||
var pitch = Input.get_action_strength("turn_up") - Input.get_action_strength("turn_down")
|
var torque = Vector3.UP * turn_input * base_turn_speed
|
||||||
|
apply_torque(torque)
|
||||||
|
print("Torque:", torque)
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
if yaw != 0 or pitch != 0:
|
|
||||||
apply_torque(Vector3(pitch, yaw, 0) * base_turn_speed)
|
|
||||||
|
|
||||||
func sync_ship_state():
|
func sync_ship_state():
|
||||||
if global_position != previous_position:
|
if global_position != previous_position:
|
||||||
@ -97,8 +116,19 @@ func set_piloting_player(player: Player):
|
|||||||
else:
|
else:
|
||||||
print("The ship is no longer piloted.")
|
print("The ship is no longer piloted.")
|
||||||
|
|
||||||
|
|
||||||
func remove_piloting_player():
|
func remove_piloting_player():
|
||||||
piloting_player = null
|
piloting_player = null
|
||||||
ship_is_piloted = false
|
ship_is_piloted = false
|
||||||
print("The ship is no longer piloted.")
|
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.")
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
[ext_resource type="Script" path="res://assets/core/ships/test-ship/test_ship.gd" id="1_yql7r"]
|
[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://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="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"]
|
[sub_resource type="BoxShape3D" id="BoxShape3D_kbheo"]
|
||||||
size = Vector3(12.0762, 9.20947, 45.9958)
|
size = Vector3(12.0762, 9.20947, 45.9958)
|
||||||
@ -20,10 +20,8 @@ script = ExtResource("1_yql7r")
|
|||||||
ship_area = NodePath("Area3D")
|
ship_area = NodePath("Area3D")
|
||||||
ship_helm = NodePath("ShipHelm")
|
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)
|
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"]
|
[node name="HelmLockPos" type="Marker3D" parent="ShipHelm"]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.345567, 1)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.345567, 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user