Preliminary multiplayer capability (origin stuff disabled for now)
This commit is contained in:
parent
73baafbd6c
commit
f0c4263675
18 changed files with 704 additions and 99 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
# Godot 4+ specific ignores
|
||||
.godot/
|
||||
/android/
|
||||
build/
|
||||
|
|
106
demo/aircraft/fixed_wing_aircraft.tscn
Normal file
106
demo/aircraft/fixed_wing_aircraft.tscn
Normal file
|
@ -0,0 +1,106 @@
|
|||
[gd_scene load_steps=14 format=3 uid="uid://dcnk85lpgfq3t"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bddnsq0h2tpf" path="res://scripts/aircraft/nodes/fixed_wing_aircraft.gd" id="1_grgqm"]
|
||||
[ext_resource type="Resource" uid="uid://dpk3bgq54ajul" path="res://demo/airfoils/symmetric.tres" id="2_og0eu"]
|
||||
[ext_resource type="Resource" uid="uid://p2i7a806s6gs" path="res://demo/propulsion/electric_motor.tres" id="3_v3vjn"]
|
||||
[ext_resource type="Script" uid="uid://qjdma7j2qrns" path="res://scripts/aircraft/resources/fixed_wing_aircraft_performance.gd" id="4_8tl6d"]
|
||||
[ext_resource type="Script" uid="uid://pc3j1c6e1ra7" path="res://scripts/aircraft/nodes/flight_sim_controller.gd" id="5_g0q8o"]
|
||||
[ext_resource type="Script" uid="uid://ddh4omp23xc58" path="res://scripts/origin/region_transform.gd" id="6_f0486"]
|
||||
|
||||
[sub_resource type="Curve" id="Curve_s1s6j"]
|
||||
_limits = [0.0, 0.5, 0.0, 20.0]
|
||||
_data = [Vector2(0, 0.5), 0.0, 0.0, 0, 0, Vector2(20, 0), -0.082397, 0.0, 0, 0]
|
||||
point_count = 2
|
||||
|
||||
[sub_resource type="Curve" id="Curve_onvmd"]
|
||||
_limits = [0.0, 2.0, 0.0, 30.0]
|
||||
_data = [Vector2(0, 2), 0.0, 0.0, 0, 0, Vector2(30, 0), -0.199316, 0.0, 0, 0]
|
||||
point_count = 2
|
||||
|
||||
[sub_resource type="Curve" id="Curve_oeqrt"]
|
||||
_limits = [0.0, 0.202247, 0.0, 10.0]
|
||||
_data = [Vector2(0, 0.202247), 0.0, 0.0, 0, 0, Vector2(10, 0), -0.0393259, 0.0, 0, 0]
|
||||
point_count = 2
|
||||
|
||||
[sub_resource type="Resource" id="Resource_onu7k"]
|
||||
script = ExtResource("4_8tl6d")
|
||||
horizontal_surface = ExtResource("2_og0eu")
|
||||
horizontal_area = 21.8
|
||||
horizontal_aspect_ratio = 5.83
|
||||
vertical_surface = ExtResource("2_og0eu")
|
||||
vertical_area = 5.0
|
||||
vertical_aspect_ratio = 5.0
|
||||
propultion = ExtResource("3_v3vjn")
|
||||
base_thrust = 100000.0
|
||||
empty_mass = 3463.0
|
||||
roll_axis = Vector3(0, 0.1, -1)
|
||||
pitch_power = SubResource("Curve_s1s6j")
|
||||
yaw_power = SubResource("Curve_oeqrt")
|
||||
roll_power = SubResource("Curve_onvmd")
|
||||
metadata/_custom_type_script = "uid://qjdma7j2qrns"
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_u10mr"]
|
||||
radius = 8.0
|
||||
|
||||
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_2wqbq"]
|
||||
properties/0/path = NodePath("FlightSimController:pitch")
|
||||
properties/0/spawn = true
|
||||
properties/0/replication_mode = 2
|
||||
properties/1/path = NodePath("FlightSimController:yaw")
|
||||
properties/1/spawn = true
|
||||
properties/1/replication_mode = 2
|
||||
properties/2/path = NodePath("FlightSimController:roll")
|
||||
properties/2/spawn = true
|
||||
properties/2/replication_mode = 2
|
||||
properties/3/path = NodePath("FlightSimController:throttle")
|
||||
properties/3/spawn = true
|
||||
properties/3/replication_mode = 2
|
||||
properties/4/path = NodePath("FlightSimController:brake")
|
||||
properties/4/spawn = true
|
||||
properties/4/replication_mode = 2
|
||||
|
||||
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_grgqm"]
|
||||
properties/0/path = NodePath(".:position")
|
||||
properties/0/spawn = true
|
||||
properties/0/replication_mode = 2
|
||||
properties/1/path = NodePath(".:rotation")
|
||||
properties/1/spawn = true
|
||||
properties/1/replication_mode = 2
|
||||
properties/2/path = NodePath(".:initial_speed")
|
||||
properties/2/spawn = true
|
||||
properties/2/replication_mode = 0
|
||||
properties/3/path = NodePath(".:multiplayer_authority")
|
||||
properties/3/spawn = true
|
||||
properties/3/replication_mode = 2
|
||||
properties/4/path = NodePath(".:velocity")
|
||||
properties/4/spawn = true
|
||||
properties/4/replication_mode = 1
|
||||
|
||||
[node name="FixedWingAircraft" type="CharacterBody3D" node_paths=PackedStringArray("controller")]
|
||||
script = ExtResource("1_grgqm")
|
||||
performance = SubResource("Resource_onu7k")
|
||||
controller = NodePath("FlightSimController")
|
||||
initial_speed = 100.0
|
||||
metadata/_custom_type_script = "uid://bddnsq0h2tpf"
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("SphereShape3D_u10mr")
|
||||
|
||||
[node name="FlightSimController" type="Node" parent="."]
|
||||
script = ExtResource("5_g0q8o")
|
||||
pitch_speed = 4.0
|
||||
yaw_speed = 4.0
|
||||
roll_speed = 3.0
|
||||
throttle = 0.5
|
||||
metadata/_custom_type_script = "uid://pc3j1c6e1ra7"
|
||||
|
||||
[node name="RegionTransform" type="Node" parent="." node_paths=PackedStringArray("target")]
|
||||
script = ExtResource("6_f0486")
|
||||
target = NodePath("..")
|
||||
metadata/_custom_type_script = "uid://ddh4omp23xc58"
|
||||
|
||||
[node name="InputSynchronizer" type="MultiplayerSynchronizer" parent="."]
|
||||
replication_config = SubResource("SceneReplicationConfig_2wqbq")
|
||||
|
||||
[node name="ServerSynchronizer" type="MultiplayerSynchronizer" parent="."]
|
||||
replication_config = SubResource("SceneReplicationConfig_grgqm")
|
71
demo/demo.gd
71
demo/demo.gd
|
@ -1,4 +1,73 @@
|
|||
extends Node3D
|
||||
|
||||
# Script stolen/modified from https://godotengine.org/article/multiplayer-in-godot-4-0-scene-replication
|
||||
|
||||
func _ready() -> void:
|
||||
RegionOrigin.anchor = $FixedWingAircraft/RegionTransform
|
||||
# We only need to spawn players on the server.
|
||||
if not multiplayer.is_server():
|
||||
return
|
||||
|
||||
multiplayer.peer_connected.connect(add_player)
|
||||
multiplayer.peer_disconnected.connect(del_player)
|
||||
|
||||
# Spawn already connected players.
|
||||
for id in multiplayer.get_peers():
|
||||
add_player(id)
|
||||
#set_up_remote_character(node: Node)
|
||||
|
||||
# Spawn the local player unless this is a dedicated server export.
|
||||
if not OS.has_feature("dedicated_server"):
|
||||
add_player(1)
|
||||
#set_up_local_character(1)
|
||||
|
||||
|
||||
func _exit_tree() -> void:
|
||||
if not multiplayer.is_server():
|
||||
return
|
||||
multiplayer.peer_connected.disconnect(add_player)
|
||||
multiplayer.peer_disconnected.disconnect(del_player)
|
||||
|
||||
|
||||
func add_player(id: int) -> void:
|
||||
var character := preload("res://demo/aircraft/fixed_wing_aircraft.tscn").instantiate() as FixedWingAircraft
|
||||
# Set player id.
|
||||
character.multiplayer_authority = id
|
||||
#character.set_multiplayer_authority(id)
|
||||
# Randomize character position.
|
||||
#var pos := Vector2.from_angle(randf() * 2 * PI)
|
||||
character.position = Vector3(randf() * 10.0 - 5.0, 100.0, randf() * 10.0 - 5.0)
|
||||
character.name = str(id)
|
||||
$Players.add_child(character, true)
|
||||
if id == multiplayer.get_unique_id():
|
||||
set_up_local_character(id)
|
||||
else:
|
||||
set_up_remote_character(character)
|
||||
|
||||
|
||||
func del_player(id: int) -> void:
|
||||
if not $Players.has_node(str(id)):
|
||||
return
|
||||
$Players.get_node(str(id)).queue_free()
|
||||
|
||||
func set_up_local_character(id: int) -> void:
|
||||
if not $Players.has_node(str(id)):
|
||||
return
|
||||
var local_player := $Players.get_node(str(id)) as FixedWingAircraft
|
||||
# Tie the camera to it
|
||||
var remote := RemoteTransform3D.new()
|
||||
local_player.add_child(remote)
|
||||
remote.remote_path = remote.get_path_to($Camera3D)
|
||||
# Set up the HUD
|
||||
($CanvasLayer/HUD as HUD).source = local_player
|
||||
|
||||
func set_up_remote_character(node: Node3D) -> void:
|
||||
# Add the roc model
|
||||
var roc := preload("res://demo/models/roc.dae").instantiate() as Node3D
|
||||
roc.rotate(Vector3.UP, PI)
|
||||
node.add_child(roc)
|
||||
|
||||
func _on_multiplayer_spawner_spawned(node: Node) -> void:
|
||||
if node.name == str(multiplayer.get_unique_id()):
|
||||
set_up_local_character(multiplayer.get_unique_id())
|
||||
elif node is FixedWingAircraft:
|
||||
set_up_remote_character(node as Node3D)
|
||||
|
|
|
@ -1,14 +1,8 @@
|
|||
[gd_scene load_steps=20 format=3 uid="uid://d20jwlre5rc5m"]
|
||||
[gd_scene load_steps=9 format=3 uid="uid://d20jwlre5rc5m"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cdk7y1rat3juk" path="res://demo/demo.gd" id="1_oeqrt"]
|
||||
[ext_resource type="Texture2D" uid="uid://bruwqvb6qrsfn" path="res://demo/textures/untexture.png" id="1_ytiva"]
|
||||
[ext_resource type="Script" uid="uid://bddnsq0h2tpf" path="res://scripts/aircraft/nodes/fixed_wing_aircraft.gd" id="2_dar0o"]
|
||||
[ext_resource type="Resource" uid="uid://dpk3bgq54ajul" path="res://demo/airfoils/symmetric.tres" id="3_u10mr"]
|
||||
[ext_resource type="Script" uid="uid://qjdma7j2qrns" path="res://scripts/aircraft/resources/fixed_wing_aircraft_performance.gd" id="4_onu7k"]
|
||||
[ext_resource type="Resource" uid="uid://p2i7a806s6gs" path="res://demo/propulsion/electric_motor.tres" id="4_s1s6j"]
|
||||
[ext_resource type="Script" uid="uid://pc3j1c6e1ra7" path="res://scripts/aircraft/nodes/flight_sim_controller.gd" id="5_s1s6j"]
|
||||
[ext_resource type="Script" uid="uid://tgj0rvn5wj8t" path="res://demo/hud.gd" id="6_onu7k"]
|
||||
[ext_resource type="Script" uid="uid://ddh4omp23xc58" path="res://scripts/origin/region_transform.gd" id="7_onvmd"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_j5lb4"]
|
||||
albedo_texture = ExtResource("1_ytiva")
|
||||
|
@ -16,52 +10,7 @@ uv1_scale = Vector3(100, 100, 100)
|
|||
|
||||
[sub_resource type="PlaneMesh" id="PlaneMesh_5hjng"]
|
||||
material = SubResource("StandardMaterial3D_j5lb4")
|
||||
size = Vector2(1000, 1000)
|
||||
center_offset = Vector3(500, 0, 500)
|
||||
|
||||
[sub_resource type="Curve" id="Curve_s1s6j"]
|
||||
_limits = [0.0, 0.5, 0.0, 20.0]
|
||||
_data = [Vector2(0, 0.5), 0.0, 0.0, 0, 0, Vector2(20, 0), -0.082397, 0.0, 0, 0]
|
||||
point_count = 2
|
||||
|
||||
[sub_resource type="Curve" id="Curve_onvmd"]
|
||||
_limits = [0.0, 2.0, 0.0, 30.0]
|
||||
_data = [Vector2(0, 2), 0.0, 0.0, 0, 0, Vector2(30, 0), -0.199316, 0.0, 0, 0]
|
||||
point_count = 2
|
||||
|
||||
[sub_resource type="Curve" id="Curve_oeqrt"]
|
||||
_limits = [0.0, 0.202247, 0.0, 10.0]
|
||||
_data = [Vector2(0, 0.202247), 0.0, 0.0, 0, 0, Vector2(10, 0), -0.0393259, 0.0, 0, 0]
|
||||
point_count = 2
|
||||
|
||||
[sub_resource type="Resource" id="Resource_onu7k"]
|
||||
script = ExtResource("4_onu7k")
|
||||
horizontal_surface = ExtResource("3_u10mr")
|
||||
horizontal_area = 21.8
|
||||
horizontal_aspect_ratio = 5.83
|
||||
horizontal_sweep = 0.0
|
||||
vertical_surface = ExtResource("3_u10mr")
|
||||
vertical_area = 5.0
|
||||
vertical_aspect_ratio = 5.0
|
||||
vertical_sweep = 0.0
|
||||
propultion = ExtResource("4_s1s6j")
|
||||
base_thrust = 100000.0
|
||||
base_drag = 0.0
|
||||
empty_mass = 3463.0
|
||||
yaw_axis = Vector3(0, -1, 0)
|
||||
roll_axis = Vector3(0, 0.1, -1)
|
||||
pitch_stability = 0.0
|
||||
yaw_stability = 0.0
|
||||
roll_stability = 0.0
|
||||
reference_ias_mps = 100.0
|
||||
braking_power = 0.0
|
||||
pitch_power = SubResource("Curve_s1s6j")
|
||||
yaw_power = SubResource("Curve_oeqrt")
|
||||
roll_power = SubResource("Curve_onvmd")
|
||||
metadata/_custom_type_script = "uid://qjdma7j2qrns"
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_u10mr"]
|
||||
radius = 8.0
|
||||
size = Vector2(2000, 2000)
|
||||
|
||||
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_onu7k"]
|
||||
|
||||
|
@ -80,34 +29,9 @@ script = ExtResource("1_oeqrt")
|
|||
[node name="Ground" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("PlaneMesh_5hjng")
|
||||
|
||||
[node name="FixedWingAircraft" type="CharacterBody3D" parent="." node_paths=PackedStringArray("controller")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 10, 0)
|
||||
script = ExtResource("2_dar0o")
|
||||
performance = SubResource("Resource_onu7k")
|
||||
controller = NodePath("FlightSimController")
|
||||
initial_speed = 100.0
|
||||
metadata/_custom_type_script = "uid://bddnsq0h2tpf"
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="FixedWingAircraft"]
|
||||
shape = SubResource("SphereShape3D_u10mr")
|
||||
|
||||
[node name="FlightSimController" type="Node" parent="FixedWingAircraft"]
|
||||
script = ExtResource("5_s1s6j")
|
||||
pitch_speed = 4.0
|
||||
yaw_speed = 4.0
|
||||
roll_speed = 3.0
|
||||
metadata/_custom_type_script = "uid://pc3j1c6e1ra7"
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="FixedWingAircraft"]
|
||||
|
||||
[node name="RegionTransform" type="Node" parent="FixedWingAircraft" node_paths=PackedStringArray("target")]
|
||||
script = ExtResource("7_onvmd")
|
||||
target = NodePath("..")
|
||||
metadata/_custom_type_script = "uid://ddh4omp23xc58"
|
||||
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||
|
||||
[node name="HUD" type="Control" parent="CanvasLayer" node_paths=PackedStringArray("source")]
|
||||
[node name="HUD" type="Control" parent="CanvasLayer"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
|
@ -115,7 +39,6 @@ anchor_bottom = 1.0
|
|||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("6_onu7k")
|
||||
source = NodePath("../../FixedWingAircraft")
|
||||
|
||||
[node name="TAS_Label" type="Label" parent="CanvasLayer/HUD"]
|
||||
layout_mode = 0
|
||||
|
@ -145,3 +68,13 @@ environment = SubResource("Environment_onvmd")
|
|||
|
||||
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
|
||||
transform = Transform3D(-4.37114e-08, -0.984808, 0.173648, 0, 0.173648, 0.984808, -1, 4.30473e-08, -7.5904e-09, 0, 0, 0)
|
||||
|
||||
[node name="MultiplayerSpawner" type="MultiplayerSpawner" parent="."]
|
||||
_spawnable_scenes = PackedStringArray("uid://dcnk85lpgfq3t")
|
||||
spawn_path = NodePath("../Players")
|
||||
|
||||
[node name="Players" type="Node3D" parent="."]
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="."]
|
||||
|
||||
[connection signal="spawned" from="MultiplayerSpawner" to="." method="_on_multiplayer_spawner_spawned"]
|
||||
|
|
|
@ -9,7 +9,8 @@ extends Control
|
|||
@onready var relative_velocity_label := $RelativeVelocityLabel as Label
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
tas_label.text = "TAS: %s" % source.m_tas
|
||||
aoa_label.text = "AOA: %s" % rad_to_deg(source.m_aoa)
|
||||
sideslip_label.text = "Sideslip: %s" % rad_to_deg(source.m_sideslip)
|
||||
relative_velocity_label.text = "V: %s" % source.m_relative_velocity
|
||||
if (source):
|
||||
tas_label.text = "TAS: %s" % source.m_tas
|
||||
aoa_label.text = "AOA: %s" % rad_to_deg(source.m_aoa)
|
||||
sideslip_label.text = "Sideslip: %s" % rad_to_deg(source.m_sideslip)
|
||||
relative_velocity_label.text = "V: %s" % source.m_relative_velocity
|
||||
|
|
117
demo/menu.gd
Normal file
117
demo/menu.gd
Normal file
|
@ -0,0 +1,117 @@
|
|||
extends Node
|
||||
|
||||
const PORT := 28002
|
||||
const MAX_CLIENTS := 2
|
||||
|
||||
@export
|
||||
var multiplayer_scene: PackedScene
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
PlayerData.player1_index = 1
|
||||
($Main/PlayButton as Button).grab_focus.call_deferred()
|
||||
|
||||
|
||||
func _on_play_button_pressed() -> void:
|
||||
multiplayer.multiplayer_peer = OfflineMultiplayerPeer.new()
|
||||
get_tree().change_scene_to_file("res://demo/demo.tscn")
|
||||
|
||||
|
||||
func _on_host_button_pressed() -> void:
|
||||
($Main as Control).hide()
|
||||
($Host as Control).show()
|
||||
var peer := ENetMultiplayerPeer.new()
|
||||
multiplayer.peer_connected.connect(_on_host_joined)
|
||||
multiplayer.peer_disconnected.connect(_on_host_left)
|
||||
peer.create_server(PORT, MAX_CLIENTS)
|
||||
multiplayer.multiplayer_peer = peer
|
||||
|
||||
|
||||
func _on_join_button_pressed() -> void:
|
||||
($Main as Control).hide()
|
||||
($Join as Control).show()
|
||||
|
||||
|
||||
func _on_exit_button_pressed() -> void:
|
||||
get_tree().quit()
|
||||
|
||||
|
||||
func _on_back_from_host_button_pressed() -> void:
|
||||
($Host as Control).hide()
|
||||
($Main as Control).show()
|
||||
PlayerData.player2_index = 0
|
||||
multiplayer.peer_connected.disconnect(_on_host_joined)
|
||||
multiplayer.peer_disconnected.disconnect(_on_host_left)
|
||||
_on_host_left(0)
|
||||
multiplayer.multiplayer_peer = OfflineMultiplayerPeer.new()
|
||||
|
||||
|
||||
func _on_back_from_join_button_pressed() -> void:
|
||||
($Join as Control).hide()
|
||||
($Main as Control).show()
|
||||
($Join/PlayerJoinedLabel as Label).text = ""
|
||||
PlayerData.player2_index = 0
|
||||
multiplayer.connected_to_server.disconnect(_on_client_joined)
|
||||
multiplayer.server_disconnected.disconnect(_on_client_left)
|
||||
multiplayer.connection_failed.disconnect(_on_client_failed_to_connect)
|
||||
multiplayer.multiplayer_peer = OfflineMultiplayerPeer.new()
|
||||
|
||||
|
||||
func _on_join_room_button_pressed() -> void:
|
||||
var peer := ENetMultiplayerPeer.new()
|
||||
var address := ($Join/AddressBar as LineEdit).text
|
||||
if (address == ""):
|
||||
address = "127.0.0.1"
|
||||
multiplayer.connected_to_server.connect(_on_client_joined)
|
||||
multiplayer.server_disconnected.connect(_on_client_left)
|
||||
multiplayer.connection_failed.connect(_on_client_failed_to_connect)
|
||||
peer.create_client(address, PORT)
|
||||
multiplayer.multiplayer_peer = peer
|
||||
|
||||
|
||||
func _on_host_joined(id: int) -> void:
|
||||
PlayerData.player2_index = id
|
||||
($Host/PlayerHostedLabel as Label).text = "Player has joined."
|
||||
($Host/PlayMultiplayerButton as Button).disabled = false
|
||||
|
||||
|
||||
func _on_host_left(_id: int) -> void:
|
||||
($Host/PlayerHostedLabel as Label).text = "Waiting for player to join..."
|
||||
($Host/PlayMultiplayerButton as Button).disabled = true
|
||||
|
||||
|
||||
func _on_client_joined() -> void:
|
||||
PlayerData.player2_index = multiplayer.get_unique_id()
|
||||
($Join/PlayerJoinedLabel as Label).text = "Player has joined."
|
||||
|
||||
|
||||
func _on_client_left() -> void:
|
||||
($Join/PlayerJoinedLabel as Label).text = "Server has closed."
|
||||
|
||||
|
||||
func _on_client_failed_to_connect() -> void:
|
||||
($Join/PlayerJoinedLabel as Label).text = "Connection failed."
|
||||
|
||||
|
||||
func _on_play_multiplayer_button_pressed() -> void:
|
||||
if multiplayer.is_server():
|
||||
_hide_menu.rpc()
|
||||
_play_multiplayer.call_deferred()
|
||||
|
||||
|
||||
func _play_multiplayer() -> void:
|
||||
var level := $Level
|
||||
for c in level.get_children():
|
||||
level.remove_child(c)
|
||||
c.queue_free()
|
||||
var mp := multiplayer_scene.instantiate()
|
||||
level.add_child(mp)
|
||||
|
||||
|
||||
@rpc("authority", "call_local", "reliable")
|
||||
func _hide_menu() -> void:
|
||||
($Join as Control).hide()
|
||||
($Main as Control).hide()
|
||||
($Host as Control).hide()
|
||||
($Background as Control).hide()
|
||||
($Title as Control).hide()
|
1
demo/menu.gd.uid
Normal file
1
demo/menu.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://cmt5cqjlcnpls
|
204
demo/menu.tscn
Normal file
204
demo/menu.tscn
Normal file
|
@ -0,0 +1,204 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://b4luon6xvu53c"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cmt5cqjlcnpls" path="res://demo/menu.gd" id="1_ux1fr"]
|
||||
[ext_resource type="PackedScene" uid="uid://d20jwlre5rc5m" path="res://demo/demo.tscn" id="2_ouk20"]
|
||||
|
||||
[node name="Menu" type="Node"]
|
||||
script = ExtResource("1_ux1fr")
|
||||
multiplayer_scene = ExtResource("2_ouk20")
|
||||
|
||||
[node name="Level" type="Node" parent="."]
|
||||
|
||||
[node name="Background" type="ColorRect" parent="."]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
color = Color(0, 0, 0, 1)
|
||||
|
||||
[node name="Title" type="Label" parent="."]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = 64.0
|
||||
offset_bottom = -662.0
|
||||
grow_horizontal = 2
|
||||
theme_override_font_sizes/font_size = 30
|
||||
text = "SparkyGD"
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="Main" type="Control" parent="."]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="PlayButton" type="Button" parent="Main"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = 104.0
|
||||
offset_bottom = -512.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
focus_neighbor_bottom = NodePath("../ExitButton")
|
||||
focus_next = NodePath("../ExitButton")
|
||||
text = "Play"
|
||||
|
||||
[node name="HostButton" type="Button" parent="Main"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = 140.0
|
||||
offset_bottom = -477.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
text = "Host"
|
||||
|
||||
[node name="JoinButton" type="Button" parent="Main"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 1.0
|
||||
offset_top = 177.0
|
||||
offset_right = 1.0
|
||||
offset_bottom = -440.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
text = "Join"
|
||||
|
||||
[node name="ExitButton" type="Button" parent="Main"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = 214.0
|
||||
offset_bottom = -403.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
focus_neighbor_top = NodePath("../PlayButton")
|
||||
focus_previous = NodePath("../PlayButton")
|
||||
text = "Exit"
|
||||
|
||||
[node name="Host" type="Control" parent="."]
|
||||
visible = false
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="PlayMultiplayerButton" type="Button" parent="Host"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = 106.0
|
||||
offset_bottom = -630.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
focus_neighbor_bottom = NodePath("../BackFromHostButton")
|
||||
focus_next = NodePath("../BackFromHostButton")
|
||||
disabled = true
|
||||
text = "Play"
|
||||
|
||||
[node name="BackFromHostButton" type="Button" parent="Host"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = 138.0
|
||||
offset_bottom = -598.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
focus_neighbor_top = NodePath("../PlayMultiplayerButton")
|
||||
focus_previous = NodePath("../PlayMultiplayerButton")
|
||||
text = "Back"
|
||||
|
||||
[node name="PlayerHostedLabel" type="Label" parent="Host"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = 170.0
|
||||
offset_bottom = -566.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
text = "Waiting for player to join..."
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="Join" type="Control" parent="."]
|
||||
visible = false
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="AddressBar" type="LineEdit" parent="Join"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = 106.0
|
||||
offset_bottom = -630.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
placeholder_text = "IP Address or Domain"
|
||||
alignment = 1
|
||||
|
||||
[node name="JoinRoomButton" type="Button" parent="Join"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = 138.0
|
||||
offset_bottom = -598.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
text = "Join"
|
||||
|
||||
[node name="BackFromJoinButton" type="Button" parent="Join"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = 170.0
|
||||
offset_bottom = -566.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
focus_neighbor_top = NodePath("../PlayButton")
|
||||
focus_previous = NodePath("../PlayButton")
|
||||
text = "Back"
|
||||
|
||||
[node name="PlayerJoinedLabel" type="Label" parent="Join"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = 201.0
|
||||
offset_bottom = -535.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="MultiplayerSpawner" type="MultiplayerSpawner" parent="."]
|
||||
_spawnable_scenes = PackedStringArray("uid://d20jwlre5rc5m")
|
||||
spawn_path = NodePath("../Level")
|
||||
|
||||
[connection signal="pressed" from="Main/PlayButton" to="." method="_on_play_button_pressed"]
|
||||
[connection signal="pressed" from="Main/HostButton" to="." method="_on_host_button_pressed"]
|
||||
[connection signal="pressed" from="Main/JoinButton" to="." method="_on_join_button_pressed"]
|
||||
[connection signal="pressed" from="Main/ExitButton" to="." method="_on_exit_button_pressed"]
|
||||
[connection signal="pressed" from="Host/PlayMultiplayerButton" to="." method="_on_play_multiplayer_button_pressed"]
|
||||
[connection signal="pressed" from="Host/BackFromHostButton" to="." method="_on_back_from_host_button_pressed"]
|
||||
[connection signal="pressed" from="Join/JoinRoomButton" to="." method="_on_join_room_button_pressed"]
|
||||
[connection signal="pressed" from="Join/BackFromJoinButton" to="." method="_on_back_from_join_button_pressed"]
|
26
demo/models/roc.dae
Normal file
26
demo/models/roc.dae
Normal file
File diff suppressed because one or more lines are too long
40
demo/models/roc.dae.import
Normal file
40
demo/models/roc.dae.import
Normal file
|
@ -0,0 +1,40 @@
|
|||
[remap]
|
||||
|
||||
importer="scene"
|
||||
importer_version=1
|
||||
type="PackedScene"
|
||||
uid="uid://b02d3mh841kjo"
|
||||
path="res://.godot/imported/roc.dae-81d2b3a307e83b949f66b9a9007aae9e.scn"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://demo/models/roc.dae"
|
||||
dest_files=["res://.godot/imported/roc.dae-81d2b3a307e83b949f66b9a9007aae9e.scn"]
|
||||
|
||||
[params]
|
||||
|
||||
nodes/root_type=""
|
||||
nodes/root_name=""
|
||||
nodes/root_script=null
|
||||
nodes/apply_root_scale=true
|
||||
nodes/root_scale=100.0
|
||||
nodes/import_as_skeleton_bones=false
|
||||
nodes/use_name_suffixes=true
|
||||
nodes/use_node_type_suffixes=true
|
||||
meshes/ensure_tangents=true
|
||||
meshes/generate_lods=true
|
||||
meshes/create_shadow_meshes=true
|
||||
meshes/light_baking=1
|
||||
meshes/lightmap_texel_size=0.2
|
||||
meshes/force_disable_compression=false
|
||||
skins/use_named_skins=true
|
||||
animation/import=true
|
||||
animation/fps=30
|
||||
animation/trimming=false
|
||||
animation/remove_immutable_tracks=true
|
||||
animation/import_rest_as_RESET=false
|
||||
import_script/path=""
|
||||
materials/extract=0
|
||||
materials/extract_format=0
|
||||
materials/extract_path=""
|
||||
_subresources={}
|
BIN
demo/models/roc.png
Normal file
BIN
demo/models/roc.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.4 KiB |
41
demo/models/roc.png.import
Normal file
41
demo/models/roc.png.import
Normal file
|
@ -0,0 +1,41 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://d0acg4tridswa"
|
||||
path.s3tc="res://.godot/imported/roc.png-9b877bc5e169ea6dd0f8e0216594f55a.s3tc.ctex"
|
||||
metadata={
|
||||
"imported_formats": ["s3tc_bptc"],
|
||||
"vram_texture": true
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://demo/models/roc.png"
|
||||
dest_files=["res://.godot/imported/roc.png-9b877bc5e169ea6dd0f8e0216594f55a.s3tc.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=2
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=true
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=0
|
6
demo/player_data.gd
Normal file
6
demo/player_data.gd
Normal file
|
@ -0,0 +1,6 @@
|
|||
extends Node
|
||||
|
||||
@export
|
||||
var player1_index := 1
|
||||
@export
|
||||
var player2_index := 0
|
1
demo/player_data.gd.uid
Normal file
1
demo/player_data.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://cuwoplv86o82q
|
42
export_presets.cfg
Normal file
42
export_presets.cfg
Normal file
|
@ -0,0 +1,42 @@
|
|||
[preset.0]
|
||||
|
||||
name="Linux"
|
||||
platform="Linux"
|
||||
runnable=true
|
||||
advanced_options=false
|
||||
dedicated_server=false
|
||||
custom_features=""
|
||||
export_filter="all_resources"
|
||||
include_filter=""
|
||||
exclude_filter=""
|
||||
export_path="build/SparkyGD.x86_64"
|
||||
patches=PackedStringArray()
|
||||
encryption_include_filters=""
|
||||
encryption_exclude_filters=""
|
||||
seed=0
|
||||
encrypt_pck=false
|
||||
encrypt_directory=false
|
||||
script_export_mode=2
|
||||
|
||||
[preset.0.options]
|
||||
|
||||
custom_template/debug=""
|
||||
custom_template/release=""
|
||||
debug/export_console_wrapper=1
|
||||
binary_format/embed_pck=false
|
||||
texture_format/s3tc_bptc=true
|
||||
texture_format/etc2_astc=false
|
||||
shader_baker/enabled=false
|
||||
binary_format/architecture="x86_64"
|
||||
ssh_remote_deploy/enabled=false
|
||||
ssh_remote_deploy/host="user@host_ip"
|
||||
ssh_remote_deploy/port="22"
|
||||
ssh_remote_deploy/extra_args_ssh=""
|
||||
ssh_remote_deploy/extra_args_scp=""
|
||||
ssh_remote_deploy/run_script="#!/usr/bin/env bash
|
||||
export DISPLAY=:0
|
||||
unzip -o -q \"{temp_dir}/{archive_name}\" -d \"{temp_dir}\"
|
||||
\"{temp_dir}/{exe_name}\" {cmd_args}"
|
||||
ssh_remote_deploy/cleanup_script="#!/usr/bin/env bash
|
||||
kill $(pgrep -x -f \"{temp_dir}/{exe_name} {cmd_args}\")
|
||||
rm -rf \"{temp_dir}\""
|
|
@ -11,14 +11,15 @@ config_version=5
|
|||
[application]
|
||||
|
||||
config/name="SparkyGD"
|
||||
run/main_scene="uid://d20jwlre5rc5m"
|
||||
config/features=PackedStringArray("4.4", "Forward Plus")
|
||||
run/main_scene="uid://b4luon6xvu53c"
|
||||
config/features=PackedStringArray("4.5", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[autoload]
|
||||
|
||||
Atmosphere="*res://scripts/aircraft/nodes/atmosphere.gd"
|
||||
RegionOrigin="*res://scripts/origin/region_origin.gd"
|
||||
PlayerData="*res://demo/player_data.gd"
|
||||
|
||||
[debug]
|
||||
|
||||
|
@ -27,7 +28,6 @@ gdscript/warnings/unsafe_property_access=2
|
|||
gdscript/warnings/unsafe_method_access=2
|
||||
gdscript/warnings/unsafe_cast=1
|
||||
gdscript/warnings/unsafe_call_argument=2
|
||||
gdscript/warnings/return_value_discarded=1
|
||||
|
||||
[input]
|
||||
|
||||
|
|
|
@ -6,6 +6,11 @@ extends CharacterBody3D
|
|||
|
||||
@export var initial_speed: float
|
||||
|
||||
@export var multiplayer_authority := 1 :
|
||||
set(id):
|
||||
multiplayer_authority = id
|
||||
set_multiplayer_authority.call_deferred(id)
|
||||
|
||||
#var acceleration := Vector3
|
||||
#var angular_velocity := Vector3
|
||||
#var angular_acceleration := Vector3
|
||||
|
@ -22,8 +27,8 @@ var m_is_landed := false
|
|||
func _ready() -> void:
|
||||
velocity = -global_basis.z * initial_speed
|
||||
m_relative_velocity = transform.basis.inverse() * velocity
|
||||
m_tas = _tas()
|
||||
m_ias = _ias()
|
||||
m_tas = _tas(m_relative_velocity)
|
||||
m_ias = _ias(m_relative_velocity)
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
|
||||
|
@ -34,8 +39,8 @@ func _physics_process(delta: float) -> void:
|
|||
m_sideslip = -atan2(m_relative_velocity.x, -m_relative_velocity.z)
|
||||
if m_sideslip > PI:
|
||||
m_sideslip -= TAU
|
||||
m_tas = _tas()
|
||||
m_ias = _ias()
|
||||
m_tas = _tas(m_relative_velocity)
|
||||
m_ias = _ias(m_relative_velocity)
|
||||
|
||||
# aero
|
||||
var vel_forward := m_relative_velocity.normalized()
|
||||
|
@ -79,14 +84,20 @@ func _physics_process(delta: float) -> void:
|
|||
rotate_object_local(steering_axis.normalized(), steering_axis.length())
|
||||
|
||||
move_and_slide()
|
||||
m_region_transform.sync_from_transform()
|
||||
#m_region_transform.sync_from_transform()
|
||||
#if !is_landed:
|
||||
# _fly()
|
||||
#else:
|
||||
# taxi()
|
||||
#ResetControls()
|
||||
|
||||
#func _sync()
|
||||
@rpc("authority", "call_remote", "unreliable_ordered")
|
||||
func _sync(pos: Vector3, rot: Basis, vel: Vector3, steering_axis: Vector3) -> void:
|
||||
# Don't snap to the correct location, because that will look bad.
|
||||
# Instead, just nudge it in the right direction.
|
||||
#var rtt: float = multiplayer.get_peers().
|
||||
#transform.basis = rot.rotated(steering_axis.normalized(), steering_axis.length() * )
|
||||
pass
|
||||
|
||||
func _get_steering_axis() -> Vector3:
|
||||
var pitch_effect := Vector3.RIGHT * performance.pitch_power.sample(absf(rad_to_deg(m_aoa))) * controller.pitch
|
||||
|
@ -192,11 +203,11 @@ func _thrust() -> float:
|
|||
# mAngularVelocity = new Vector3(horizAirfoil.getMoment(degAoA) * horizLiftPerCoeff, vertAirfoil.getMoment(degSideslip) * vertLiftPerCoeff, 0f);
|
||||
# mAngularVelocity += new Vector3(-moment * Mathf.Cos(Vector3.Angle(Physics.gravity, transform.up) * Mathf.Deg2Rad) * horizLiftPerCoeff, 0.0f, 0.0f)
|
||||
|
||||
func _tas() -> float:
|
||||
return sqrt(m_relative_velocity.z * m_relative_velocity.z + m_relative_velocity.y * m_relative_velocity.y) * -sign(m_relative_velocity.z)
|
||||
func _tas(relative_velocity: Vector3) -> float:
|
||||
return relative_velocity.length() * -sign(relative_velocity.z)
|
||||
|
||||
func _ias() -> float:
|
||||
return _tas() * sqrt(Atmosphere.density_by_alt(position.y, true))
|
||||
func _ias(relative_velocity: Vector3) -> float:
|
||||
return _tas(relative_velocity) * sqrt(Atmosphere.density_by_alt(position.y, true))
|
||||
|
||||
#func _
|
||||
|
||||
|
|
|
@ -15,7 +15,13 @@ extends AircraftController
|
|||
@export var roll_speed := 1.0
|
||||
@export var throttle_speed := 1.0
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
#func _ready() -> void:
|
||||
# Only process for the local player.
|
||||
# set_process(get_multiplayer_authority() == multiplayer.get_unique_id())
|
||||
# if get_multiplayer_authority() == multiplayer.get_unique_id():
|
||||
# print("Multiplayer auth: ", str(get_multiplayer_authority()))
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if get_multiplayer_authority() == multiplayer.get_unique_id():
|
||||
var pitch_target := Input.get_axis(pitch_down, pitch_up)
|
||||
var pitch_diff := pitch_target - pitch
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue