Save working changes
This commit is contained in:
parent
d547d6260b
commit
6229e64b42
Binary file not shown.
@ -4,9 +4,14 @@ extends Interactable
|
|||||||
|
|
||||||
var parent_ship: Ship
|
var parent_ship: Ship
|
||||||
|
|
||||||
|
var uuid: String = ""
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
parent_ship = get_parent() #sets the parent ship to the ship that the helm is placed on
|
uuid = NetworkManager.register_node(self)
|
||||||
|
NetworkManager.property_update_received.connect(_on_property_update)
|
||||||
|
parent_ship = get_parent().get_parent() #sets the parent ship to the ship that the helm is placed on
|
||||||
|
NetworkManager.sync_property(uuid, "parent_ship", parent_ship)
|
||||||
|
|
||||||
|
|
||||||
func interact():
|
func interact():
|
||||||
@ -17,3 +22,12 @@ func interact():
|
|||||||
elif parent_ship.ship_is_piloted:
|
elif parent_ship.ship_is_piloted:
|
||||||
player_reference.set_is_piloting(false)
|
player_reference.set_is_piloting(false)
|
||||||
parent_ship.ship_is_piloted = false
|
parent_ship.ship_is_piloted = false
|
||||||
|
parent_ship._sync_piloting_state()
|
||||||
|
|
||||||
|
|
||||||
|
func _on_property_update(uuid: String, property_name: String, value: Variant):
|
||||||
|
if NetworkManager.node_map.has(uuid):
|
||||||
|
var node = NetworkManager.node_map[uuid]
|
||||||
|
node.set(property_name, value)
|
||||||
|
else:
|
||||||
|
printerr("Received property update but node_id is wrong? Expected " + str(uuid) + " but got " + str(uuid))
|
||||||
|
@ -3,6 +3,7 @@ class_name Ship
|
|||||||
extends RigidBody3D
|
extends RigidBody3D
|
||||||
|
|
||||||
@export var player_detection_area: Area3D
|
@export var player_detection_area: Area3D
|
||||||
|
@export var helm_location_marker: Marker3D
|
||||||
|
|
||||||
var ship_helm_scene: PackedScene = load("res://assets/core/interactables/ship-helm/ship-helm.tscn")
|
var ship_helm_scene: PackedScene = load("res://assets/core/interactables/ship-helm/ship-helm.tscn")
|
||||||
|
|
||||||
@ -13,7 +14,7 @@ var ship_id: int = 0
|
|||||||
var ship_is_piloted: bool = false
|
var ship_is_piloted: bool = false
|
||||||
var current_level
|
var current_level
|
||||||
|
|
||||||
var _ignore_next_call := false
|
var uuid: String = ""
|
||||||
|
|
||||||
@export_range(0.01, 1.0, 0.01) var base_turn_speed: float = 0.35
|
@export_range(0.01, 1.0, 0.01) var base_turn_speed: float = 0.35
|
||||||
@export var max_turn_speed: float = 0.5
|
@export var max_turn_speed: float = 0.5
|
||||||
@ -24,6 +25,11 @@ var _ignore_next_call := false
|
|||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
uuid = NetworkManager.register_node(self)
|
||||||
|
NetworkManager.property_update_received.connect(_on_property_update)
|
||||||
|
|
||||||
|
if !NetworkManager.is_host: return
|
||||||
|
|
||||||
#connect signals
|
#connect signals
|
||||||
player_detection_area.body_entered.connect(_on_area_3d_body_entered)
|
player_detection_area.body_entered.connect(_on_area_3d_body_entered)
|
||||||
player_detection_area.body_exited.connect(_on_area_3d_body_exited)
|
player_detection_area.body_exited.connect(_on_area_3d_body_exited)
|
||||||
@ -34,7 +40,8 @@ func _ready():
|
|||||||
GameConsole.log_debug("Ship ID: " + str(ship_id))
|
GameConsole.log_debug("Ship ID: " + str(ship_id))
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(_delta):
|
||||||
|
if !NetworkManager.is_host: return
|
||||||
if ship_is_piloted:
|
if ship_is_piloted:
|
||||||
var turn_speed = base_turn_speed / max(mass, 1)
|
var turn_speed = base_turn_speed / max(mass, 1)
|
||||||
var lift_speed = base_lift_speed / max(mass, 1)
|
var lift_speed = base_lift_speed / max(mass, 1)
|
||||||
@ -56,8 +63,8 @@ func _physics_process(delta):
|
|||||||
target_velocity = -transform.basis.z * top_speed
|
target_velocity = -transform.basis.z * top_speed
|
||||||
elif Input.is_action_pressed("move_backwards"):
|
elif Input.is_action_pressed("move_backwards"):
|
||||||
target_velocity = transform.basis.z * top_speed
|
target_velocity = transform.basis.z * top_speed
|
||||||
var acceleration = (target_velocity - linear_velocity) * acceleration
|
var current_acceleration = (target_velocity - linear_velocity) * acceleration
|
||||||
apply_central_force(acceleration * mass)
|
apply_central_force(current_acceleration * mass)
|
||||||
if linear_velocity.length() > top_speed:
|
if linear_velocity.length() > top_speed:
|
||||||
linear_velocity = linear_velocity.normalized() * top_speed
|
linear_velocity = linear_velocity.normalized() * top_speed
|
||||||
|
|
||||||
@ -67,8 +74,14 @@ func _physics_process(delta):
|
|||||||
global_rotation.x = lerpf(global_rotation.x, 0, 0.1)
|
global_rotation.x = lerpf(global_rotation.x, 0, 0.1)
|
||||||
global_rotation.z = lerpf(global_rotation.z, 0, 0.1)
|
global_rotation.z = lerpf(global_rotation.z, 0, 0.1)
|
||||||
|
|
||||||
|
# Networking
|
||||||
|
NetworkManager.sync_property(uuid, "global_position", global_position)
|
||||||
|
NetworkManager.sync_property(uuid, "global_rotation", global_rotation)
|
||||||
|
NetworkManager.sync_property(uuid, "piloting_player", piloting_player)
|
||||||
|
|
||||||
|
|
||||||
func _on_area_3d_body_entered(body: Node3D) -> void:
|
func _on_area_3d_body_entered(body: Node3D) -> void:
|
||||||
|
if !NetworkManager.is_host: return
|
||||||
if body is Player and body.get_parent() != self:
|
if body is Player and body.get_parent() != self:
|
||||||
body.ship_entered(self)
|
body.ship_entered(self)
|
||||||
piloting_player = body
|
piloting_player = body
|
||||||
@ -77,6 +90,7 @@ func _on_area_3d_body_entered(body: Node3D) -> void:
|
|||||||
|
|
||||||
|
|
||||||
func _on_area_3d_body_exited(body: Node3D) -> void:
|
func _on_area_3d_body_exited(body: Node3D) -> void:
|
||||||
|
if !NetworkManager.is_host: return
|
||||||
if body is Player and body.get_parent() != get_node("/root/DevLevel/"):
|
if body is Player and body.get_parent() != get_node("/root/DevLevel/"):
|
||||||
body.ship_exited()
|
body.ship_exited()
|
||||||
ship_is_piloted = false
|
ship_is_piloted = false
|
||||||
@ -86,6 +100,19 @@ func _on_area_3d_body_exited(body: Node3D) -> void:
|
|||||||
|
|
||||||
|
|
||||||
func _add_ship_helm(_ship_helm_scene: PackedScene):
|
func _add_ship_helm(_ship_helm_scene: PackedScene):
|
||||||
|
if !NetworkManager.is_host: return
|
||||||
var ship_helm = _ship_helm_scene.instantiate()
|
var ship_helm = _ship_helm_scene.instantiate()
|
||||||
add_child(ship_helm)
|
helm_location_marker.add_child(ship_helm)
|
||||||
ship_helm = get_node("ShipHelm")
|
ship_helm = helm_location_marker.get_node("ShipHelm")
|
||||||
|
|
||||||
|
|
||||||
|
func _on_property_update(uuid: String, property_name: String, value: Variant):
|
||||||
|
if NetworkManager.node_map.has(uuid):
|
||||||
|
var node = NetworkManager.node_map[uuid]
|
||||||
|
node.set(property_name, value)
|
||||||
|
else:
|
||||||
|
printerr("Received property update but node_id is wrong? Expected " + str(uuid) + " but got " + str(uuid))
|
||||||
|
|
||||||
|
|
||||||
|
func _sync_piloting_state():
|
||||||
|
NetworkManager.sync_property(uuid, "ship_is_piloted", ship_is_piloted)
|
||||||
|
@ -16,13 +16,14 @@ size = Vector3(5, 0.15, 20)
|
|||||||
[sub_resource type="BoxShape3D" id="BoxShape3D_7o08p"]
|
[sub_resource type="BoxShape3D" id="BoxShape3D_7o08p"]
|
||||||
size = Vector3(4.99609, 3.11252, 20.0022)
|
size = Vector3(4.99609, 3.11252, 20.0022)
|
||||||
|
|
||||||
[node name="ShuttleClass" type="RigidBody3D" node_paths=PackedStringArray("player_detection_area")]
|
[node name="ShuttleClass" type="RigidBody3D" node_paths=PackedStringArray("player_detection_area", "helm_location_marker")]
|
||||||
collision_layer = 8
|
collision_layer = 8
|
||||||
collision_mask = 200
|
collision_mask = 200
|
||||||
mass = 700.0
|
mass = 700.0
|
||||||
gravity_scale = 0.0
|
gravity_scale = 0.0
|
||||||
script = ExtResource("1_ghft7")
|
script = ExtResource("1_ghft7")
|
||||||
player_detection_area = NodePath("PlayerDetectionArea")
|
player_detection_area = NodePath("PlayerDetectionArea")
|
||||||
|
helm_location_marker = NodePath("HelmLocationMarker")
|
||||||
|
|
||||||
[node name="ShipToShipCol" type="CollisionShape3D" parent="."]
|
[node name="ShipToShipCol" type="CollisionShape3D" parent="."]
|
||||||
shape = SubResource("BoxShape3D_6gbwt")
|
shape = SubResource("BoxShape3D_6gbwt")
|
||||||
@ -44,3 +45,6 @@ shape = SubResource("BoxShape3D_6gbwt")
|
|||||||
[node name="PlayerDetectionAreaCol" type="CollisionShape3D" parent="PlayerDetectionArea"]
|
[node name="PlayerDetectionAreaCol" type="CollisionShape3D" parent="PlayerDetectionArea"]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.47652, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.47652, 0)
|
||||||
shape = SubResource("BoxShape3D_7o08p")
|
shape = SubResource("BoxShape3D_7o08p")
|
||||||
|
|
||||||
|
[node name="HelmLocationMarker" type="Marker3D" parent="."]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.1, 0)
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user