Compare commits

..

61 Commits

Author SHA1 Message Date
cef87a7e2f Merge pull request 'Ship mostly works' (#10) from feature/ship-syncing into develop
Reviewed-on: https://git.bellsworne.tech/Bellsworne/steamforged-skies/pulls/10
Reviewed-by: Gary Steven Keough <gskeough@bellsworne.com>
2024-12-29 04:35:51 +00:00
3d00b049e5 add export link to player hud node 2024-12-28 23:33:18 -05:00
cb8da7c59e fix player hud doubling 2024-12-28 23:26:02 -05:00
0f94338b37 please work 2024-12-28 22:25:09 -06:00
1197618572 torque 2024-12-28 22:15:31 -06:00
b003aec5a4 clamp again 2024-12-28 22:09:29 -06:00
c3285652ea clamp 2024-12-28 22:03:41 -06:00
2e5428ae91 Messing with interpolation 2024-12-28 21:58:09 -06:00
b1b6cdd712 Changing up authority 2024-12-28 21:50:31 -06:00
999a88c402 reparent stuff fixed 2024-12-28 21:43:16 -06:00
f4b7bf282d UHHHHHHHHHH 2024-12-28 21:30:14 -06:00
7f05c190ce remove bad logging 2024-12-28 21:20:25 -06:00
283d313f88 maybe maybe maybe 2024-12-28 21:17:55 -06:00
4bf6eaae0b Full ship rework 2024-12-28 21:08:39 -06:00
c84681fdfa Added new methods to network manager 2024-12-28 20:32:43 -06:00
d225145927 Merge remote-tracking branch 'origin/feature/ship-syncing' into feature/ship-syncing 2024-12-28 19:51:21 -06:00
8b85544255 ship is still snapping for host, testing multiplayer 2024-12-28 19:51:09 -06:00
80165ca131 minor player script fixes 2024-12-28 20:15:40 -05:00
d0a2a74e14 increase ship's overall speed, correct player head syncing 2024-12-28 19:59:30 -05:00
ec6325fb9e Fix player head rotation syncing 2024-12-28 19:31:36 -05:00
beae9284e7 New ship new me 2024-12-28 18:18:36 -06:00
904141e541 fix player head rotation again 2024-12-28 18:28:26 -05:00
df077c24dd Remove uneeded method in the hull 2024-12-28 17:19:02 -06:00
ddbd76c1e1 fix player face 2024-12-28 18:13:56 -05:00
3ce0fc5311 Fixing helm 2024-12-28 17:12:23 -06:00
e8cf9e47c0 New AI slop 2024-12-28 17:06:46 -06:00
8b824d49da stupid quaternions 2024-12-28 16:41:28 -06:00
69014169f2 Handle corrections 2024-12-28 16:36:51 -06:00
a6ba12bd76 Forgot to actually create the sync_to_peer function in networkmanager 2024-12-28 16:23:10 -06:00
501085bf57 it didnt work 2024-12-28 16:19:01 -06:00
b50bdb52ec Redo the entire ship script. Works in singleplayer, lets hope it works in multiplayer 2024-12-28 15:42:19 -06:00
633678d0ea Some additional steps to try and fix the ship sync issue 2024-12-28 15:22:55 -06:00
defd05a826 Merge remote-tracking branch 'origin/develop' into feature/ship-syncing 2024-12-28 11:25:53 -06:00
359e4554ba More AI lol 2024-12-19 20:45:24 -06:00
13a1845e6b Sync player piloting state 2024-12-19 20:38:54 -06:00
fa7c562bb5 AI Slop 2024-12-19 20:25:54 -06:00
2b5935feae The AI made this 2024-12-19 20:18:58 -06:00
dc635482c8 Actually lerping the positions 2024-12-19 19:51:21 -06:00
e43e0cc890 Piloting player 2024-12-19 19:45:25 -06:00
636b44793e Buffer 2024-12-19 19:37:58 -06:00
d82445114d Potential ship fix 2024-12-19 09:04:45 -06:00
dd7aa1899f invert player sprite 2024-12-18 23:46:31 -05:00
52ed547ab2 Potential fix for ship sync 2024-12-18 22:44:08 -06:00
cf3beff3e5 Touch up player for personality 2024-12-18 23:26:14 -05:00
cb95f57f32 Merge branch 'develop' into feature/ship-syncing 2024-12-18 21:57:57 -05:00
a7f7a35266 fix goofy ass sky shader 2024-12-17 20:41:05 -05:00
e2a6d529b6 fix player camera stuck when pliloting 2024-12-16 22:01:44 -05:00
51dc6406a8 revert properly to is host check 2024-12-16 21:57:38 -05:00
12231567b8 revert 2024-12-16 21:52:42 -05:00
f30b5b79d3 save changes 2024-12-16 21:50:21 -05:00
37021e494d fixy 2024-12-16 21:42:34 -05:00
72cf4c0ff1 save changes 2024-12-16 21:40:36 -05:00
c96b136d3e Save changes 2024-12-16 21:30:40 -05:00
4cd4150a3a ur avatarz 2024-12-15 23:25:15 -05:00
8e3027715a GET ME GOING BABY 2024-12-15 23:11:39 -05:00
bb867c427e Update changes 2024-12-15 23:04:20 -05:00
159f5ae629 Save working changes 2024-12-15 22:55:48 -05:00
5b58093138 Correct packet abuse 2024-12-15 22:44:28 -05:00
55d28cd242 update 2024-12-15 22:43:03 -05:00
820f641ebc Save working changes 2024-12-15 22:37:49 -05:00
6229e64b42 Save working changes 2024-12-15 22:29:02 -05:00
14 changed files with 370 additions and 131 deletions

View File

@ -3,25 +3,26 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://fwub8fvl2u4i"
path="res://.godot/imported/ps1hagrid.png-c23425fa4ddfd6de7aebcbcf4a03083a.ctex"
path.s3tc="res://.godot/imported/ps1hagrid.png-c23425fa4ddfd6de7aebcbcf4a03083a.s3tc.ctex"
metadata={
"vram_texture": false
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://addons/ingameconsole/ps1hagrid.png"
dest_files=["res://.godot/imported/ps1hagrid.png-c23425fa4ddfd6de7aebcbcf4a03083a.ctex"]
dest_files=["res://.godot/imported/ps1hagrid.png-c23425fa4ddfd6de7aebcbcf4a03083a.s3tc.ctex"]
[params]
compress/mode=0
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
@ -31,4 +32,4 @@ process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
detect_3d/compress_to=0

View File

@ -1,19 +1,15 @@
class_name ShipHelm
extends Interactable
var parent_ship: Ship
func _ready():
parent_ship = get_parent() #sets the parent ship to the ship that the helm is placed on
@export var parent_ship: Ship
func interact():
if !parent_ship.ship_is_piloted:
player_reference.set_is_piloting(true)
parent_ship.ship_is_piloted = true
if player_reference.is_network_authority:
if !parent_ship.ship_is_piloted:
player_reference.set_is_piloting(true)
parent_ship.set_piloting_player(player_reference)
elif parent_ship.ship_is_piloted:
player_reference.set_is_piloting(false)
parent_ship.remove_piloting_player()
elif parent_ship.ship_is_piloted:
player_reference.set_is_piloting(false)
parent_ship.ship_is_piloted = false

View File

@ -17,6 +17,7 @@ var steam_id: int = 0
var steam_username: String = ""
var avatar_texture_cache: Dictionary = {}
var is_host: bool = false
var host_id: int
var uuid_counter: int = 0
@ -203,6 +204,7 @@ func host_lobby():
if lobby_id == 0:
Steam.createLobby(lobby_type, lobby_members_max)
is_host = true
host_id = steam_id
else:
printerr("Cannot host lobby, already in a lobby")
@ -211,12 +213,14 @@ func join_lobby(this_lobby_id: int):
print("Attempting to join lobby: " + str(this_lobby_id))
lobby_members.clear()
Steam.joinLobby(this_lobby_id)
host_id = Steam.getLobbyOwner(this_lobby_id)
func leave_lobby():
if lobby_id != 0:
Steam.leaveLobby(lobby_id)
lobby_id = 0
host_id = 0
for this_member in lobby_members:
if this_member["steam_id"] != steam_id:
@ -270,8 +274,14 @@ func send_p2p_packet(target: int, packet_data: Dictionary) -> void:
if this_member['steam_id'] != steam_id:
Steam.sendP2PPacket(this_member['steam_id'], this_data, send_type, channel)
#print("Sent packet to %s." % this_member['steam_name'])
# Else send it to someone specific
# If sending a packet to everyone except the host
elif target == 1:
if lobby_members.size() > 1:
# Loop through all members that aren't the host
for this_member in lobby_members:
if this_member['steam_id'] != host_id:
Steam.sendP2PPacket(this_member['steam_id'], this_data, send_type, channel)
# Else send it to someone specific
else:
Steam.sendP2PPacket(target, this_data, send_type, channel)
@ -318,7 +328,6 @@ func read_p2p_packet() -> void:
if "message" in readable_data and readable_data["message"] == "property_update":
if "node_id" in readable_data and "property_name" in readable_data and "value" in readable_data:
emit_signal("property_update_received", readable_data["node_id"], readable_data["property_name"], readable_data["value"])
#print("Received property update packet for node %d: %s = %s" % [readable_data["node_id"], readable_data["property_name"], readable_data["value"]])
func register_node(node: Node) -> String:
@ -379,6 +388,7 @@ func _on_game_started():
var player: Player = player_scene.instantiate()
player.name = "Player_" + str(member["steam_id"])
player.username = Steam.getFriendPersonaName(member["steam_id"])
player.steam_id = member["steam_id"]
if member["steam_id"] == steam_id:
player.is_network_authority = true
@ -388,8 +398,21 @@ func _on_game_started():
level.add_child(player)
func sync_property(node_id: String, property_name: String, value: Variant):
func sync_property_to_host(node_id: String, property_name: String, value: Variant):
var packet_data = {"message":"property_update", "node_id": node_id, "property_name": property_name, "value": value}
send_p2p_packet(host_id, packet_data)
func sync_property_to_peer(node_id: String, property_name: String, value: Variant, target_peer: int):
var packet_data = {"message":"property_update", "node_id": node_id, "property_name": property_name, "value": value}
send_p2p_packet(target_peer, packet_data)
func sync_property_to_all(node_id: String, property_name: String, value: Variant):
var packet_data = {"message":"property_update", "node_id": node_id, "property_name":property_name, "value":value}
send_p2p_packet(0, packet_data)
func sync_property_to_all_except_host(node_id: String, property_name: String, value: Variant):
var packet_data = {"message":"property_update", "node_id": node_id, "property_name":property_name, "value":value}
send_p2p_packet(1, packet_data)

View File

@ -1,6 +1,7 @@
[gd_scene load_steps=11 format=3 uid="uid://c6w0ivy4hetrl"]
[gd_scene load_steps=12 format=3 uid="uid://c6w0ivy4hetrl"]
[ext_resource type="Script" path="res://assets/core/player-controller/scripts/player.gd" id="1_bv7t4"]
[ext_resource type="Texture2D" uid="uid://fwub8fvl2u4i" path="res://addons/ingameconsole/ps1hagrid.png" id="2_omgn1"]
[ext_resource type="Script" path="res://assets/core/player-controller/scripts/player_interacter.gd" id="2_wvu3d"]
[ext_resource type="Script" path="res://assets/core/player-controller/scripts/player_hud.gd" id="3_02ne1"]
[ext_resource type="Shader" path="res://assets/core/player-controller/scenes/inverted_crosshair.gdshader" id="3_rakxt"]
@ -8,13 +9,14 @@
[sub_resource type="CapsuleMesh" id="CapsuleMesh_v7b3h"]
radius = 0.35
height = 1.5
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_qlkab"]
radius = 0.35
[sub_resource type="CameraAttributesPractical" id="CameraAttributesPractical_fqbrh"]
auto_exposure_enabled = true
auto_exposure_max_sensitivity = 700.0
[sub_resource type="SphereMesh" id="SphereMesh_vu2l8"]
radius = 0.35
height = 0.7
[sub_resource type="ShaderMaterial" id="ShaderMaterial_wmxrr"]
shader = ExtResource("3_rakxt")
@ -22,10 +24,15 @@ shader = ExtResource("3_rakxt")
[sub_resource type="ShaderMaterial" id="ShaderMaterial_0n7pd"]
shader = ExtResource("3_rakxt")
[node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("camera")]
[node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("camera", "neck", "player_avatar_face", "body", "head", "player_hud")]
collision_mask = 242
script = ExtResource("1_bv7t4")
camera = NodePath("Neck/Camera3D")
neck = NodePath("Neck")
player_avatar_face = NodePath("Neck/Camera3D/PlayerAvatarFace")
body = NodePath("Body")
head = NodePath("Neck/Head")
player_hud = NodePath("PlayerHUD")
[node name="PlayerTag" type="Label3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.26654, 0)
@ -34,7 +41,8 @@ visibility_range_end = 15.0
billboard = 1
text = "username"
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
[node name="Body" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.5, 0)
mesh = SubResource("CapsuleMesh_v7b3h")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
@ -44,7 +52,6 @@ shape = SubResource("CapsuleShape3D_qlkab")
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.65, 0)
[node name="Camera3D" type="Camera3D" parent="Neck"]
attributes = SubResource("CameraAttributesPractical_fqbrh")
[node name="RayCast3D" type="RayCast3D" parent="Neck/Camera3D" node_paths=PackedStringArray("player")]
target_position = Vector3(0, 0, -2.5)
@ -52,6 +59,16 @@ collision_mask = 256
script = ExtResource("2_wvu3d")
player = NodePath("../../..")
[node name="PlayerAvatarFace" type="Sprite3D" parent="Neck/Camera3D"]
transform = Transform3D(-0.1, 0, -8.74228e-09, 0, 0.1, 0, 8.74228e-09, 0, -0.1, 0, 0, -0.349588)
flip_h = true
shaded = true
double_sided = false
texture = ExtResource("2_omgn1")
[node name="Head" type="MeshInstance3D" parent="Neck"]
mesh = SubResource("SphereMesh_vu2l8")
[node name="PlayerHUD" type="CanvasLayer" parent="." node_paths=PackedStringArray("fps_label")]
script = ExtResource("3_02ne1")
fps_label = NodePath("Debug/HBoxContainer/VBoxContainer/MarginContainer/FPSLabel")

View File

@ -16,6 +16,12 @@ var steam_id: int = 0
@export_range(0.1, 3.0, 0.1, "or_greater") var camera_sens: float = 1.0
@export_range(0.1, 3.0, 0.1, "or_greater") var joystick_camera_sens_multiplier: float = 5.0
@export var camera: Camera3D
@export var neck: Node3D
@export var player_avatar_face: Sprite3D
@export var body: MeshInstance3D
@export var head: MeshInstance3D
@export var player_hud: CanvasLayer
var jumping: bool = false
var is_using_joystick: bool = false
@ -31,6 +37,9 @@ var current_ship: Ship
var previous_global_position: Vector3
var previous_global_rotation: Vector3
var previous_head_vert_rotation: Vector3
var neck_rotation_sync: Vector3
func _ready() -> void:
@ -39,22 +48,16 @@ func _ready() -> void:
player_tag = get_node("PlayerTag")
player_tag.text = username
player_avatar_face.texture = await NetworkManager.get_player_avatar(steam_id)
if is_network_authority:
camera.make_current()
func _unhandled_input(event: InputEvent) -> void:
if !is_network_authority: return
if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
if event is InputEventMouseMotion:
is_using_joystick = false
look_dir = event.relative * 0.001
_rotate_camera()
elif event is InputEventJoypadMotion:
is_using_joystick = true
if Input.is_action_just_pressed("jump") and !is_piloting:
jumping = true
body.hide()
head.hide()
player_avatar_face.hide()
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
else:
player_hud.hide()
func _input(event):
@ -64,11 +67,21 @@ func _input(event):
elif event.is_action_pressed("esc") and not Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
capture_mouse()
if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
if event is InputEventMouseMotion:
is_using_joystick = false
look_dir = event.relative * 0.001
_rotate_camera()
elif event is InputEventJoypadMotion:
is_using_joystick = true
if Input.is_action_just_pressed("jump") and !is_piloting:
jumping = true
func _physics_process(delta: float) -> void:
if !is_network_authority: return
if is_piloting and current_ship != null:
global_rotation.y = current_ship.global_rotation.y
velocity = Vector3.ZERO + _gravity(delta)
else:
velocity = walk(delta) + _gravity(delta) + _jump(delta)
@ -86,12 +99,17 @@ func _process(delta: float) -> void:
# If the global_position has changed, notify the NetworkManager
if previous_global_position != global_position:
NetworkManager.sync_property(network_uuid, "global_position", global_position)
NetworkManager.sync_property_to_all(network_uuid, "global_position", global_position)
previous_global_position = global_position
if previous_global_rotation != global_rotation:
NetworkManager.sync_property(network_uuid, "global_rotation", global_rotation)
NetworkManager.sync_property_to_all(network_uuid, "global_rotation", global_rotation)
previous_global_rotation = global_rotation
if previous_head_vert_rotation != neck.rotation:
NetworkManager.sync_property_to_all(network_uuid, "neck_rotation_sync", neck_rotation_sync)
previous_global_rotation = neck.rotation
func capture_mouse() -> void:
if !is_network_authority: return
@ -109,8 +127,9 @@ func _rotate_camera(sens_mod: float = 1.0) -> void:
if is_using_joystick:
camera_sens_final = camera_sens * joystick_camera_sens_multiplier
camera.rotation.y -= look_dir.x * camera_sens_final * sens_mod
camera.rotation.x = clamp(camera.rotation.x - look_dir.y * camera_sens_final * sens_mod, -1.5, 1.5)
rotation.y -= look_dir.x * camera_sens_final * sens_mod
neck.rotation.x = clamp(neck.rotation.x - look_dir.y * camera_sens_final * sens_mod, -1.5, 1.5)
neck_rotation_sync = neck.rotation
func _handle_joypad_camera_rotation(delta: float, sens_mod: float = 1.0) -> void:
@ -124,7 +143,7 @@ func _handle_joypad_camera_rotation(delta: float, sens_mod: float = 1.0) -> void
func walk(delta: float) -> Vector3:
if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
move_dir = Input.get_vector("move_left", "move_right", "move_forwards", "move_backwards")
var _forward: Vector3 = camera.global_transform.basis * Vector3(move_dir.x, 0, move_dir.y)
var _forward: Vector3 = neck.global_transform.basis * Vector3(move_dir.x, 0, move_dir.y)
var walk_dir: Vector3 = Vector3(_forward.x, 0, _forward.z).normalized()
walk_vel = walk_vel.move_toward(walk_dir * speed * move_dir.length(), acceleration * delta)
return walk_vel
@ -174,7 +193,10 @@ func ship_exited():
func _on_property_update(node_id: String, property_name: String, value: Variant) -> void:
if NetworkManager.node_map.has(node_id):
var node = NetworkManager.node_map[node_id]
node.set(property_name, value)
if property_name == "neck_rotation_sync" and !is_network_authority:
neck.rotation = value
else:
var node = NetworkManager.node_map[node_id]
node.set(property_name, value)
else:
printerr("Received property update but node_id is wrong? Expected " + str(network_uuid) + " but got " + str(node_id))

View File

@ -3,89 +3,166 @@ class_name Ship
extends RigidBody3D
@export var player_detection_area: Area3D
@export var helm_location_marker: Marker3D
@export var base_turn_speed: float = 50.0
@export var max_turn_speed: float = 50.0
@export var base_lift_speed: float = 50.0
@export var top_speed: float = 50.0
@export var move_speed: float = 50.0
@export var acceleration: float = 5.0 # Increased acceleration for smoother interpolation
@export var interpolation_damp: float = 0.1 # Damping for smoother rotation
var ship_helm_scene: PackedScene = load("res://assets/core/interactables/ship-helm/ship-helm.tscn")
var ship_helm: ShipHelm
var piloting_player: Player = null
var ship_id: int = 0
var ship_is_piloted: bool = false
var current_level
var _ignore_next_call := false
@export_range(0.01, 1.0, 0.01) var base_turn_speed: float = 0.35
@export var max_turn_speed: float = 0.5
@export_range(0.01, 1.0, 0.01) var base_lift_speed: float = 2.0
@export var top_speed: float = 5.0
@export var move_speed: float = 1.0
@export var acceleration: float = 0.1
var target_position: Vector3 = Vector3.ZERO
var target_rotation: Quaternion = Quaternion()
var predicted_position: Vector3
var predicted_rotation: Quaternion
var last_input_time: float = 0.0
var network_uuid: String = ""
func _ready():
#connect signals
player_detection_area.body_entered.connect(_on_area_3d_body_entered)
player_detection_area.body_exited.connect(_on_area_3d_body_exited)
network_uuid = NetworkManager.register_node(self)
NetworkManager.property_update_received.connect(_on_property_update)
_add_ship_helm(ship_helm_scene) #TEMPORARY TEST
# Preserve current position and rotation at the start
target_position = global_position
target_rotation = global_transform.basis.get_rotation_quaternion()
predicted_position = global_position
predicted_rotation = global_transform.basis.get_rotation_quaternion()
ship_id = randi_range(1000, 9999) #assign a random id to the ship as a unique identifier
GameConsole.log_debug("Ship ID: " + str(ship_id))
player_detection_area.body_entered.connect(_on_player_entered)
player_detection_area.body_exited.connect(_on_player_exited)
func _physics_process(delta):
func _process(delta: float):
if ship_is_piloted:
var turn_speed = base_turn_speed / max(mass, 1)
var lift_speed = base_lift_speed / max(mass, 1)
if Input.is_action_pressed("move_left"):
angular_velocity.y += turn_speed
elif Input.is_action_pressed("move_right"):
angular_velocity.y -= turn_speed
if piloting_player.steam_id == NetworkManager.steam_id:
# This player is piloting
handle_input(delta)
send_network_update()
else:
global_rotation.z = lerpf(global_rotation.z, 0, 0.8)
# Another player is piloting, interpolate
interpolate_position_and_rotation(delta)
else:
# No one is piloting, just interpolate
interpolate_position_and_rotation(delta)
if Input.is_action_pressed("jump"):
linear_velocity.y += lift_speed
elif Input.is_action_pressed("crouch"):
linear_velocity.y -= lift_speed
func handle_input(delta: float):
var forward_input = 0.0
var turn_input = 0.0
var vertical_input = 0.0
var target_velocity = Vector3.ZERO
if Input.is_action_pressed("move_forwards"):
target_velocity = -transform.basis.z * top_speed
elif Input.is_action_pressed("move_backwards"):
target_velocity = transform.basis.z * top_speed
var acceleration = (target_velocity - linear_velocity) * acceleration
apply_central_force(acceleration * mass)
if linear_velocity.length() > top_speed:
linear_velocity = linear_velocity.normalized() * top_speed
# Forward and backward movement
if Input.is_action_pressed("move_forwards"):
forward_input += 1
if Input.is_action_pressed("move_backwards"):
forward_input -= 1
angular_velocity.y = clamp(angular_velocity.y, -max_turn_speed, max_turn_speed)
# Left and right turning
if Input.is_action_pressed("move_left"):
turn_input += 1
if Input.is_action_pressed("move_right"):
turn_input -= 1
# Self level slowly
global_rotation.x = lerpf(global_rotation.x, 0, 0.1)
global_rotation.z = lerpf(global_rotation.z, 0, 0.1)
# Up and down movement
if Input.is_action_pressed("jump"):
vertical_input += 1
if Input.is_action_pressed("crouch"):
vertical_input -= 1
# Apply torque for turning
if turn_input != 0:
var torque = Vector3.UP * turn_input * base_turn_speed
apply_torque(torque)
func _on_area_3d_body_entered(body: Node3D) -> void:
# Clamp the angular velocity to the maximum turn speed
if angular_velocity.length() > max_turn_speed:
angular_velocity = angular_velocity.normalized() * max_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)
# Apply force for vertical movement
if vertical_input != 0:
var vertical_force = Vector3.UP * vertical_input * base_lift_speed
apply_central_force(vertical_force)
# Update predicted state
predicted_position = predict_position(delta)
predicted_rotation = predict_rotation(delta)
last_input_time = Time.get_ticks_msec()
func predict_position(delta: float):
var velocity = linear_velocity
return global_position + velocity * delta
func predict_rotation(delta: float):
var angular_velocity_quat = Quaternion(Vector3.UP, angular_velocity.y * delta)
return global_transform.basis.get_rotation_quaternion() * angular_velocity_quat
func interpolate_position_and_rotation(delta: float):
# Smooth interpolation with damping
global_position = lerp(global_position, target_position, 1.0 - exp(-acceleration * delta))
global_transform.basis = Basis(slerp_damp(global_transform.basis.get_rotation_quaternion(), target_rotation, interpolation_damp, 1.0))
func slerp_damp(from: Quaternion, to: Quaternion, damping: float, dt: float):
var t = 1.0 - exp(-damping * dt)
return from.slerp(to, t)
func send_network_update():
if NetworkManager.is_host and ship_is_piloted and piloting_player.steam_id == NetworkManager.steam_id:
# Host is piloting, synchronize with clients
NetworkManager.sync_property_to_all_except_host(network_uuid, "global_position", predicted_position)
NetworkManager.sync_property_to_all_except_host(network_uuid, "global_rotation", predicted_rotation)
elif !NetworkManager.is_host and ship_is_piloted and piloting_player.steam_id == NetworkManager.steam_id:
# Client is piloting, send updates to the host
NetworkManager.sync_property_to_all_except_host(network_uuid, "global_position", predicted_position)
NetworkManager.sync_property_to_all_except_host(network_uuid, "global_rotation", predicted_rotation)
func receive_global_position_update(value: Vector3):
target_position = value
func receive_global_rotation_update(value: Quaternion):
target_rotation = value
func _on_player_entered(body):
if body is Player and body.get_parent() != self:
if !body.is_network_authority: return
body.call_deferred("reparent", self, true)
body.ship_entered(self)
piloting_player = body
body.call_deferred("reparent", self, true) #reparents player onto self (RigidBody3D)
print("ENTERED")
print("Player entered the ship area.")
func _on_area_3d_body_exited(body: Node3D) -> void:
func _on_player_exited(body):
if body is Player and body.get_parent() != get_node("/root/DevLevel/"):
if !body.is_network_authority: return
body.call_deferred("reparent", get_node("/root/DevLevel/"), true)
body.ship_exited()
ship_is_piloted = false
piloting_player = null
body.call_deferred("reparent", get_node("/root/DevLevel/"), true) #reparents player back onto world node
print("EXITED")
print("Player exited the ship area.")
func set_piloting_player(player: Player):
piloting_player = player
ship_is_piloted = piloting_player != null
if piloting_player:
print("Player", piloting_player.username, "is now piloting the ship.")
else:
print("The ship is no longer piloted.")
func _add_ship_helm(_ship_helm_scene: PackedScene):
var ship_helm = _ship_helm_scene.instantiate()
add_child(ship_helm)
ship_helm = get_node("ShipHelm")
func remove_piloting_player():
piloting_player = null
ship_is_piloted = false
print("The ship is no longer piloted.")
func _on_property_update(node_id: String, property_name: String, value: Variant) -> void:
if NetworkManager.node_map.has(node_id) and node_id == network_uuid:
if property_name == "global_position":
receive_global_position_update(value)
elif property_name == "global_rotation":
receive_global_rotation_update(value)
else:
var node = NetworkManager.node_map[node_id]
node.set(property_name, value)

View File

@ -1,7 +1,8 @@
[gd_scene load_steps=7 format=3 uid="uid://y0xb2vktsr1k"]
[gd_scene load_steps=8 format=3 uid="uid://y0xb2vktsr1k"]
[ext_resource type="Script" path="res://assets/core/ships/ship_script.gd" id="1_ghft7"]
[ext_resource type="Texture2D" uid="uid://gymb0tju4y67" path="res://addons/kennysprototypetextures/Dark/texture_black (1).png" id="2_3koq8"]
[ext_resource type="PackedScene" uid="uid://dm31ddavxv5gt" path="res://assets/core/interactables/ship-helm/ship-helm.tscn" id="3_eyiku"]
[sub_resource type="BoxShape3D" id="BoxShape3D_6gbwt"]
size = Vector3(5, 0.15, 20)
@ -16,13 +17,15 @@ size = Vector3(5, 0.15, 20)
[sub_resource type="BoxShape3D" id="BoxShape3D_7o08p"]
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_mask = 200
mass = 700.0
gravity_scale = 0.0
script = ExtResource("1_ghft7")
player_detection_area = NodePath("PlayerDetectionArea")
helm_location_marker = NodePath("HelmLocationMarker")
base_lift_speed = 5.0
[node name="ShipToShipCol" type="CollisionShape3D" parent="."]
shape = SubResource("BoxShape3D_6gbwt")
@ -44,3 +47,10 @@ shape = SubResource("BoxShape3D_6gbwt")
[node name="PlayerDetectionAreaCol" type="CollisionShape3D" parent="PlayerDetectionArea"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.47652, 0)
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)
[node name="ShipHelm" parent="." node_paths=PackedStringArray("parent_ship") instance=ExtResource("3_eyiku")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -7.54699)
parent_ship = NodePath("..")

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)

View File

@ -7,6 +7,7 @@ extends RigidBody3D
var ship_id: int = 0
var ship_is_piloted: bool = false
var base_turn_speed: float = 1
var top_turn_speed: float = 50.0
var ship_lift_speed: float = 20 # Adjust this value as needed
var acceleration: float = 50
var deceleration: float = acceleration * 0.5
@ -25,11 +26,11 @@ func _ready():
func _physics_process(delta):
global_rotation.x = lerpf(global_rotation.x, 0, 0.01)
global_rotation.z = lerpf(global_rotation.z, 0, 0.01)
global_rotation.x = lerpf(global_rotation.x, 0, 0.5)
global_rotation.z = lerpf(global_rotation.z, 0, 0.5)
if ship_is_piloted:
var turn_speed = base_turn_speed / max(mass, 1)
var turn_speed = base_turn_speed / max(mass, 1) # changes speeds based on how THICC the ship is
if Input.is_action_pressed("move_left"):
angular_velocity.y += turn_speed
elif Input.is_action_pressed("move_right"):
@ -52,11 +53,7 @@ func _physics_process(delta):
if Input.is_action_pressed("crouch"):
apply_impulse(Vector3.DOWN * ship_lift_speed)
angular_velocity.y = clamp(angular_velocity.y, -0.5, 0.5)
if piloting_player != null and ship_helm.is_being_piloted:
piloting_player.global_position = ship_helm.helm_lock_pos.global_position
angular_velocity.y = clamp(angular_velocity.y, -top_turn_speed, top_turn_speed)
func _on_area_3d_body_entered(body):

33
deleteme.txt Normal file
View File

@ -0,0 +1,33 @@
Player 1: Host
Player 2: Pilot
Player 3: Neither
FOR SENDING UPDATES:
if host is pilot or no pilot, host sends ship state
if pilot, pilot sends ship state not the host
FOR RECEIVING UPDATES:
if no pilot and not host, receive updates
if no pilot and is host, do not receive updates - host is sending updates
if pilot, do not receive updates
if host and there is a pilot, receive updates from pilot
func send():
if (host == pilot or no_pilot) {
// host sends ship state
} else if (pilot) {
// pilot sends ship state
}
func receive():
if (no_pilot and not host) {
// receive updates from host
} else if (no_pilot and is_host) {
// do not receive updates - host is sending updates
} else if (pilot) {
// do not receive updates - sending updates as pilot
} else if (host and there is a pilot) {
// receive updates from pilot - receiving updates as host from pilot
}

View File

@ -37,3 +37,68 @@ unzip -o -q \"{temp_dir}/{archive_name}\" -d \"{temp_dir}\"
ssh_remote_deploy/cleanup_script="#!/usr/bin/env bash
kill $(pgrep -x -f \"{temp_dir}/{exe_name} {cmd_args}\")
rm -rf \"{temp_dir}\""
[preset.1]
name="Windows Desktop"
platform="Windows Desktop"
runnable=true
advanced_options=false
dedicated_server=false
custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=""
export_path="C:/Users/wisen/Downloads/Steamforged Skies.exe"
encryption_include_filters=""
encryption_exclude_filters=""
encrypt_pck=false
encrypt_directory=false
script_export_mode=2
[preset.1.options]
custom_template/debug=""
custom_template/release=""
debug/export_console_wrapper=1
binary_format/embed_pck=true
texture_format/s3tc_bptc=true
texture_format/etc2_astc=false
binary_format/architecture="x86_64"
codesign/enable=false
codesign/timestamp=true
codesign/timestamp_server_url=""
codesign/digest_algorithm=1
codesign/description=""
codesign/custom_options=PackedStringArray()
application/modify_resources=true
application/icon="res://assets/icon.png"
application/console_wrapper_icon=""
application/icon_interpolation=4
application/file_version="0.0.0.1"
application/product_version="0.0.0.1"
application/company_name="Bellsworne Games"
application/product_name="Steamforged Skies"
application/file_description="A steampunk airship survival game"
application/copyright=""
application/trademarks=""
application/export_angle=0
application/export_d3d12=0
application/d3d12_agility_sdk_multiarch=true
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="Expand-Archive -LiteralPath '{temp_dir}\\{archive_name}' -DestinationPath '{temp_dir}'
$action = New-ScheduledTaskAction -Execute '{temp_dir}\\{exe_name}' -Argument '{cmd_args}'
$trigger = New-ScheduledTaskTrigger -Once -At 00:00
$settings = New-ScheduledTaskSettingsSet
$task = New-ScheduledTask -Action $action -Trigger $trigger -Settings $settings
Register-ScheduledTask godot_remote_debug -InputObject $task -Force:$true
Start-ScheduledTask -TaskName godot_remote_debug
while (Get-ScheduledTask -TaskName godot_remote_debug | ? State -eq running) { Start-Sleep -Milliseconds 100 }
Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue"
ssh_remote_deploy/cleanup_script="Stop-ScheduledTask -TaskName godot_remote_debug -ErrorAction:SilentlyContinue
Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue
Remove-Item -Recurse -Force '{temp_dir}'"

View File

@ -11,7 +11,7 @@ config_version=5
[application]
config/name="Steamforged Skies"
run/main_scene="res://assets/scenes/main.tscn"
run/main_scene="res://assets/core/networking/scenes/lobby.tscn"
config/features=PackedStringArray("4.3", "Forward Plus")
config/icon="res://assets/icon.png"