From e78d11998ff11f3fa72ce809c5214240ffd04f0c Mon Sep 17 00:00:00 2001 From: bee Date: Thu, 9 Jul 2026 08:18:48 +0200 Subject: [PATCH] various fixes --- README.md | 6 +++--- main.tscn | 1 - ocean.tscn | 6 ------ scripts/camera_rig.gd | 2 +- scripts/floating_body.gd | 7 ++++--- scripts/ocean.gd | 13 +++++++++---- scripts/player_controller.gd | 12 +++++++++--- scripts/projectile.gd | 2 +- scripts/stats_label.gd | 5 ++--- scripts/weapon_slot.gd | 4 ++++ 10 files changed, 33 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 275f948..8009afa 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ TODO: DONE Controller/possession refactor (input out of Boat). -WeaponDef resource + WeaponSlot + one dumb gun that prints instead of shooting. -Projectile base (with group self-registration) + real firing. -Loadout-driven mounting. +DONE WeaponDef resource + WeaponSlot + one dumb gun that prints instead of shooting. +DONE Projectile base (with group self-registration) + real firing. +DONE Loadout-driven mounting. Second boat scene to prove the whole seam. diff --git a/main.tscn b/main.tscn index 1f8d901..e12978e 100644 --- a/main.tscn +++ b/main.tscn @@ -74,4 +74,3 @@ current_controlled = NodePath("../Boat") world_manager = NodePath("../WorldManager") camera_rig = NodePath("../CameraRig") hud = NodePath("../Hud") -throttle_ramp = null diff --git a/ocean.tscn b/ocean.tscn index 5a168cd..2b5c2d2 100644 --- a/ocean.tscn +++ b/ocean.tscn @@ -3,14 +3,8 @@ [ext_resource type="Material" uid="uid://6p5bg1nyso6d" path="res://materials/stylized_water.tres" id="1_j38dg"] [ext_resource type="Script" uid="uid://co5xetl8amg4j" path="res://scripts/ocean.gd" id="2_nb2vx"] -[sub_resource type="PlaneMesh" id="PlaneMesh_ocean"] -size = Vector2(200, 200) -subdivide_width = 200 -subdivide_depth = 200 - [node name="Ocean" type="MeshInstance3D" unique_id=521355215 groups=["follow_focus", "ocean"]] material_override = ExtResource("1_j38dg") -mesh = SubResource("PlaneMesh_ocean") script = ExtResource("2_nb2vx") sea_height = 1.0 sea_choppy = 8.0 diff --git a/scripts/camera_rig.gd b/scripts/camera_rig.gd index 4a396e4..40a58a0 100644 --- a/scripts/camera_rig.gd +++ b/scripts/camera_rig.gd @@ -30,4 +30,4 @@ func _unhandled_input(event: InputEvent) -> void: func _process(delta: float) -> void: if target: - global_position = global_position.lerp(target.global_position, follow_speed * delta) + global_position = global_position.lerp(target.global_position, 1.0 - exp(-follow_speed * delta)) diff --git a/scripts/floating_body.gd b/scripts/floating_body.gd index e0b8485..f2fc36a 100644 --- a/scripts/floating_body.gd +++ b/scripts/floating_body.gd @@ -24,7 +24,6 @@ extends RigidBody3D var _probe_offsets: Array[Vector3] = [] # local space var _ocean: Ocean -# var _probes: Array[Marker3D] = [] TODO: Probably unused var _gravity: float = ProjectSettings.get_setting("physics/3d/default_gravity") var submerged_ratio := 0.0 @@ -39,10 +38,12 @@ func _ready() -> void: if _probe_offsets.is_empty(): for col in probe_grid.x: for row in probe_grid.y: + var tx := 0.5 if probe_grid.x <= 1 else col / float(probe_grid.x - 1) + var tz := 0.5 if probe_grid.y <= 1 else row / float(probe_grid.y - 1) _probe_offsets.append(Vector3( - lerpf(-probe_extents.x, probe_extents.x, col / float(probe_grid.x - 1)), + lerpf(-probe_extents.x, probe_extents.x, tx), probe_extents.y, - lerpf(-probe_extents.z, probe_extents.z, row / float(probe_grid.y - 1)))) + lerpf(-probe_extents.z, probe_extents.z, tz))) diff --git a/scripts/ocean.gd b/scripts/ocean.gd index 3745959..dafa191 100644 --- a/scripts/ocean.gd +++ b/scripts/ocean.gd @@ -30,16 +30,21 @@ extends MeshInstance3D set(value): iter_geometry = value _push("ITER_GEOMETRY", value) -## Node the ocean mesh stays centered under (camera rig or boat). -## Half-size of the rendered ocean square, in meters. + +## Half-size of the rendered ocean square, in meters @export var render_distance := 100.0: set(value): render_distance = value if is_node_ready(): _rebuild_mesh() -## World-space distance between mesh vertices; smaller = more wave detail. -@export var vertex_spacing := 1.0 +## World-space distance between mesh vertices; smaller = more wave detail. +@export var vertex_spacing := 1.0: + set(value): + vertex_spacing = value + if is_node_ready(): + _rebuild_mesh() + var _phase := 0.0 var _wave_offset := Vector2.ZERO diff --git a/scripts/player_controller.gd b/scripts/player_controller.gd index d24dcc1..73547ff 100644 --- a/scripts/player_controller.gd +++ b/scripts/player_controller.gd @@ -3,6 +3,9 @@ extends Node @export var current_controlled : Boat: set(value): + if current_controlled != null and current_controlled != value: + current_controlled.desired_throttle = 0.0 + current_controlled.steer_input = 0.0 current_controlled = value if is_node_ready(): if current_controlled != null: @@ -57,6 +60,9 @@ func _process(delta: float) -> void: current_controlled.fire_weapons() func _possess() -> void: - camera_rig.target = current_controlled - world_manager.focus = current_controlled - hud.boat = current_controlled + if camera_rig != null: + camera_rig.target = current_controlled + if world_manager != null: + world_manager.focus = current_controlled + if hud != null: + hud.boat = current_controlled diff --git a/scripts/projectile.gd b/scripts/projectile.gd index 105cd35..eef76ff 100644 --- a/scripts/projectile.gd +++ b/scripts/projectile.gd @@ -18,7 +18,7 @@ func launch(def: AmmoDef, muzzle: Transform3D, speed_scale := 1.0) -> void: reset_physics_interpolation() func _physics_process(delta: float) -> void: - if Vector3.UP.cross(linear_velocity).length_squared() > 0.01: + if linear_velocity.length_squared() > 0.01 and absf(linear_velocity.normalized().dot(Vector3.UP)) < 0.999: look_at(global_position + linear_velocity) _time_left -= delta diff --git a/scripts/stats_label.gd b/scripts/stats_label.gd index 3571f1b..a6352f7 100644 --- a/scripts/stats_label.gd +++ b/scripts/stats_label.gd @@ -1,8 +1,7 @@ extends Label -@export var boat: Boat -@export var world: WorldManager - +var boat: Boat # Assigned by hud +var world: WorldManager # Assigned by hud func _process(_delta: float) -> void: if boat == null or world == null: diff --git a/scripts/weapon_slot.gd b/scripts/weapon_slot.gd index 4f4c47c..cfe8b1e 100644 --- a/scripts/weapon_slot.gd +++ b/scripts/weapon_slot.gd @@ -12,6 +12,10 @@ func can_mount(def: WeaponDef) -> bool: func mount(def: WeaponDef) -> bool: if not can_mount(def): + push_warning("%s can't mount %s" % [ + name, + def.display_name if def != null else "" + ]) return false unmount() weapon = def.weapon_scene.instantiate()