From e946b43db71d75f33e5b1fbc6523890bd08ba5ed Mon Sep 17 00:00:00 2001 From: bee Date: Tue, 7 Jul 2026 10:01:56 +0200 Subject: [PATCH] stuff --- hud.tscn | 20 ++++++++++++ main.tscn | 66 ++++++---------------------------------- ocean.tscn | 17 +++++++++++ player_boat.tscn | 29 ++++++++++++++++++ project.godot | 19 ++++++++++++ scripts/boat.gd | 6 ++-- scripts/floating_body.gd | 1 - scripts/game.gd | 6 ++++ scripts/game.gd.uid | 1 + scripts/hud.gd | 27 ++++++++++++++++ scripts/hud.gd.uid | 1 + scripts/stats_label.gd | 6 ++-- scripts/world_manager.gd | 4 +++ 13 files changed, 140 insertions(+), 63 deletions(-) create mode 100644 hud.tscn create mode 100644 ocean.tscn create mode 100644 player_boat.tscn create mode 100644 scripts/game.gd create mode 100644 scripts/game.gd.uid create mode 100644 scripts/hud.gd create mode 100644 scripts/hud.gd.uid diff --git a/hud.tscn b/hud.tscn new file mode 100644 index 0000000..8135100 --- /dev/null +++ b/hud.tscn @@ -0,0 +1,20 @@ +[gd_scene format=3 uid="uid://conoykdb1g38n"] + +[ext_resource type="Script" uid="uid://b500yf6hema7c" path="res://scripts/stats_label.gd" id="1_37p78"] +[ext_resource type="Script" uid="uid://b3gsctxaxjaj1" path="res://scripts/hud.gd" id="1_64ctp"] + +[node name="Hud" type="CanvasLayer" unique_id=167273188] +script = ExtResource("1_64ctp") + +[node name="StatsLabel" type="Label" parent="." unique_id=1367070931] +unique_name_in_owner = true +anchors_preset = 3 +anchor_left = 1.0 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = -76.0 +offset_top = -52.0 +grow_horizontal = 0 +grow_vertical = 0 +script = ExtResource("1_37p78") diff --git a/main.tscn b/main.tscn index f764e1d..5d57923 100644 --- a/main.tscn +++ b/main.tscn @@ -1,10 +1,9 @@ [gd_scene format=3 uid="uid://jven27ktracb"] -[ext_resource type="Material" uid="uid://6p5bg1nyso6d" path="res://materials/stylized_water.tres" id="1_water_material"] -[ext_resource type="Script" uid="uid://co5xetl8amg4j" path="res://scripts/ocean.gd" id="2_ocean_script"] -[ext_resource type="Script" uid="uid://c0n1x050jvspr" path="res://scripts/boat.gd" id="3_1bvp3"] +[ext_resource type="PackedScene" uid="uid://c6n3dg530t8oc" path="res://ocean.tscn" id="1_lquwl"] +[ext_resource type="PackedScene" uid="uid://cieiwihia8t2w" path="res://player_boat.tscn" id="2_7mycd"] [ext_resource type="Script" uid="uid://46jiwugeccqg" path="res://scripts/camera_rig.gd" id="4_1bvp3"] -[ext_resource type="Script" uid="uid://b500yf6hema7c" path="res://scripts/stats_label.gd" id="5_lquwl"] +[ext_resource type="PackedScene" uid="uid://conoykdb1g38n" path="res://hud.tscn" id="4_272bh"] [ext_resource type="Script" uid="uid://dpohf1tg5e2gs" path="res://scripts/world_manager.gd" id="6_7mycd"] [sub_resource type="ProceduralSkyMaterial" id="SkyMaterial_1"] @@ -19,11 +18,6 @@ background_mode = 2 sky = SubResource("Sky_1") tonemap_mode = 2 -[sub_resource type="PlaneMesh" id="PlaneMesh_ocean"] -size = Vector2(200, 200) -subdivide_width = 200 -subdivide_depth = 200 - [sub_resource type="BoxMesh" id="BoxMesh_seabed"] size = Vector3(200, 1, 200) @@ -33,14 +27,6 @@ albedo_color = Color(0.76, 0.7, 0.5, 1) [sub_resource type="BoxShape3D" id="BoxShape_seabed"] size = Vector3(200, 1, 200) -[sub_resource type="BoxMesh" id="BoxMesh_crate"] - -[sub_resource type="StandardMaterial3D" id="Material_crate"] -albedo_color = Color(0.72, 0.53, 0.32, 1) -roughness = 0.9 - -[sub_resource type="BoxShape3D" id="BoxShape_crate"] - [node name="Main" type="Node3D" unique_id=1242452333] [node name="WorldEnvironment" type="WorldEnvironment" parent="." unique_id=431656791] @@ -50,13 +36,7 @@ environment = SubResource("Environment_1") transform = Transform3D(1, 0, 0, 0, 0.642788, 0.766044, 0, -0.766044, 0.642788, 0, 20, 0) shadow_enabled = true -[node name="Ocean" type="MeshInstance3D" parent="." unique_id=312504233 groups=["follow_focus", "ocean"]] -material_override = ExtResource("1_water_material") -mesh = SubResource("PlaneMesh_ocean") -script = ExtResource("2_ocean_script") -sea_height = 1.0 -sea_choppy = 8.0 -metadata/follow_step = 1.0 +[node name="Ocean" parent="." unique_id=521355215 instance=ExtResource("1_lquwl")] [node name="Seabed" type="StaticBody3D" parent="." unique_id=1919476025 groups=["follow_focus"]] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -4.5, 0) @@ -68,50 +48,24 @@ surface_material_override/0 = SubResource("Material_seabed") [node name="CollisionShape3D" type="CollisionShape3D" parent="Seabed" unique_id=111957760] shape = SubResource("BoxShape_seabed") -[node name="Crate" type="RigidBody3D" parent="." unique_id=1409256205 groups=["shift_with_origin"]] +[node name="PlayerBoat" parent="." unique_id=1387061778 instance=ExtResource("2_7mycd")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3, 0) -mass = 5.0 -script = ExtResource("3_1bvp3") -buoyancy = 1.5 -full_force_depth = 0.8 -probe_extents = Vector3(0.35, 0, 2.25) - -[node name="Mesh" type="MeshInstance3D" parent="Crate" unique_id=1406951740] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 5, 0, 0, 0) -mesh = SubResource("BoxMesh_crate") -surface_material_override/0 = SubResource("Material_crate") - -[node name="CollisionShape3D" type="CollisionShape3D" parent="Crate" unique_id=1190807384] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 5, 0, 0, 0) -shape = SubResource("BoxShape_crate") [node name="CameraRig" type="Node3D" parent="." unique_id=2139913829 node_paths=PackedStringArray("target", "cam") groups=["shift_with_origin"]] transform = Transform3D(1, 0, 0, 0, 0.9396926, 0.34202012, 0, -0.34202012, 0.9396926, 0, 0, 0) script = ExtResource("4_1bvp3") -target = NodePath("../Crate") +target = NodePath("../PlayerBoat") cam = NodePath("PlayerCamera") [node name="PlayerCamera" type="Camera3D" parent="CameraRig" unique_id=553919400] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 8) -[node name="CanvasLayer" type="CanvasLayer" parent="." unique_id=1275537335] - -[node name="StatsLabel" type="Label" parent="CanvasLayer" unique_id=15552030 node_paths=PackedStringArray("boat", "world")] -anchors_preset = 3 -anchor_left = 1.0 -anchor_top = 1.0 -anchor_right = 1.0 -anchor_bottom = 1.0 -offset_left = -76.0 -offset_top = -52.0 -grow_horizontal = 0 -grow_vertical = 0 -script = ExtResource("5_lquwl") -boat = NodePath("../../Crate") -world = NodePath("../../WorldManager") +[node name="Hud" parent="." unique_id=167273188 node_paths=PackedStringArray("boat", "world") instance=ExtResource("4_272bh")] +boat = NodePath("../PlayerBoat") +world = NodePath("../WorldManager") [node name="WorldManager" type="Node" parent="." unique_id=1879897241 node_paths=PackedStringArray("focus", "ocean")] script = ExtResource("6_7mycd") -focus = NodePath("../Crate") +focus = NodePath("../PlayerBoat") ocean = NodePath("../Ocean") shift_threshold = 50.0 diff --git a/ocean.tscn b/ocean.tscn new file mode 100644 index 0000000..5a168cd --- /dev/null +++ b/ocean.tscn @@ -0,0 +1,17 @@ +[gd_scene format=3 uid="uid://c6n3dg530t8oc"] + +[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 +metadata/follow_step = 1.0 diff --git a/player_boat.tscn b/player_boat.tscn new file mode 100644 index 0000000..4d0f258 --- /dev/null +++ b/player_boat.tscn @@ -0,0 +1,29 @@ +[gd_scene format=3 uid="uid://cieiwihia8t2w"] + +[ext_resource type="Script" uid="uid://c0n1x050jvspr" path="res://scripts/boat.gd" id="1_7h74f"] + +[sub_resource type="BoxMesh" id="BoxMesh_crate"] +size = Vector3(1, 1, 5) + +[sub_resource type="StandardMaterial3D" id="Material_crate"] +albedo_color = Color(0.72, 0.53, 0.32, 1) +roughness = 0.9 + +[sub_resource type="BoxShape3D" id="BoxShape_crate"] + +[node name="PlayerBoat" type="RigidBody3D" unique_id=1387061778 groups=["shift_with_origin"]] +mass = 5.0 +script = ExtResource("1_7h74f") +buoyancy = 1.5 +full_force_depth = 0.8 +probe_extents = Vector3(0.35, 0, 2.25) +probe_grid = Vector2i(2, 5) + +[node name="Mesh" type="MeshInstance3D" parent="." unique_id=671943938] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 5, 0, 0, 0) +layers = 2 +mesh = SubResource("BoxMesh_crate") +surface_material_override/0 = SubResource("Material_crate") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="." unique_id=18200711] +shape = SubResource("BoxShape_crate") diff --git a/project.godot b/project.godot index fc1285f..0694404 100644 --- a/project.godot +++ b/project.godot @@ -14,6 +14,10 @@ config/name="boatgame" run/main_scene="res://main.tscn" config/features=PackedStringArray("4.7", "Forward Plus") +[autoload] + +Game="*uid://dtkqmj8h5mg8y" + [display] window/stretch/mode="canvas_items" @@ -46,11 +50,26 @@ throttle_stop={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":88,"key_label":0,"unicode":120,"location":0,"echo":false,"script":null) ] } +restart={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194332,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +] +} + +[layer_names] + +3d_physics/layer_1="terrain" +3d_physics/layer_2="player" +3d_physics/layer_3="enemies" +3d_physics/layer_4="projectiles" +3d_physics/layer_5="pickups" [physics] 3d/physics_engine="Jolt Physics" +common/physics_interpolation=true [rendering] rendering_device/driver.windows="d3d12" +rendering_device/fallback_to_d3d12=false diff --git a/scripts/boat.gd b/scripts/boat.gd index 47219b5..277b7f6 100644 --- a/scripts/boat.gd +++ b/scripts/boat.gd @@ -25,6 +25,9 @@ func _physics_process(delta: float) -> void: throttle = move_toward(throttle, desired_throttle, throttle_response * delta) + if submerged_ratio <= 0.0: + return # airborne: no thrust, no rudder, no keel + # boat's forward direction, flattened onto the water plane var forward := -global_basis.z forward.y = 0.0 @@ -40,9 +43,6 @@ func _physics_process(delta: float) -> void: var rudder_bite := clampf(forward_speed / 3.0, -1.0, 1.0) apply_torque(Vector3.UP * steer_input * rudder_strength * rudder_bite * mass * submerged_ratio) - if submerged_ratio <= 0.0: - return # airborne: no thrust, no rudder, no keelffffff - # --- keel: kill sideways sliding --- var right := global_basis.x right.y = 0.0 diff --git a/scripts/floating_body.gd b/scripts/floating_body.gd index b5e7f54..89783a0 100644 --- a/scripts/floating_body.gd +++ b/scripts/floating_body.gd @@ -57,7 +57,6 @@ func _physics_process(_delta: float) -> void: var factor := clampf(depth / full_force_depth, 0.0, 1.0) submerged_ratio += factor / _probe_offsets.size() var force := Vector3.UP * _gravity * mass * buoyancy * factor / _probe_offsets.size() - apply_force(force, pos - global_position) var r := pos - global_position # velocity of this specific point on the hull (body motion + rotation) var point_velocity := linear_velocity + angular_velocity.cross(r) diff --git a/scripts/game.gd b/scripts/game.gd new file mode 100644 index 0000000..71d7c9e --- /dev/null +++ b/scripts/game.gd @@ -0,0 +1,6 @@ +# scripts/game.gd — autoloaded as "Game" +extends Node + +func _unhandled_input(event: InputEvent) -> void: + if event.is_action_pressed("restart"): + get_tree().reload_current_scene() diff --git a/scripts/game.gd.uid b/scripts/game.gd.uid new file mode 100644 index 0000000..e2da0ce --- /dev/null +++ b/scripts/game.gd.uid @@ -0,0 +1 @@ +uid://dtkqmj8h5mg8y diff --git a/scripts/hud.gd b/scripts/hud.gd new file mode 100644 index 0000000..ff53eae --- /dev/null +++ b/scripts/hud.gd @@ -0,0 +1,27 @@ +class_name Hud +extends CanvasLayer + +## The HUD's only inputs. Everything inside hud.tscn gets its references +## from here -- nothing inside the scene reaches out on its own. + +@export var boat: Boat: + set(value): + boat = value + if is_node_ready(): + _distribute() +@export var world: WorldManager: + set(value): + world = value + if is_node_ready(): + _distribute() + +@onready var _stats_label: Label = %StatsLabel + + +func _ready() -> void: + _distribute() + + +func _distribute() -> void: + _stats_label.boat = boat + _stats_label.world = world diff --git a/scripts/hud.gd.uid b/scripts/hud.gd.uid new file mode 100644 index 0000000..ba394f6 --- /dev/null +++ b/scripts/hud.gd.uid @@ -0,0 +1 @@ +uid://b3gsctxaxjaj1 diff --git a/scripts/stats_label.gd b/scripts/stats_label.gd index d9a1027..6e740cc 100644 --- a/scripts/stats_label.gd +++ b/scripts/stats_label.gd @@ -5,7 +5,7 @@ extends Label func _process(_delta: float) -> void: - if boat == null: + if boat == null or world == null: text = "no boat" return @@ -22,6 +22,6 @@ Position: (%.0f, %.0f) boat.throttle * 100.0, speed, boat.submerged_ratio * 100.0, - boat.global_position.x, - boat.global_position.z, + pos.x, + pos.z, ] diff --git a/scripts/world_manager.gd b/scripts/world_manager.gd index bcebabb..84e8009 100644 --- a/scripts/world_manager.gd +++ b/scripts/world_manager.gd @@ -22,6 +22,8 @@ func true_position(node: Node3D) -> Vector3: func _physics_process(_delta: float) -> void: + if focus == null: + return _maybe_shift_origin() _recenter_followers() @@ -34,6 +36,7 @@ func _maybe_shift_origin() -> void: origin_offset += shift for node in get_tree().get_nodes_in_group("shift_with_origin"): node.global_position -= shift + node.reset_physics_interpolation() ocean.shift_origin(shift) @@ -45,3 +48,4 @@ func _recenter_followers() -> void: if new_x != node.global_position.x or new_z != node.global_position.z: node.global_position.x = new_x node.global_position.z = new_z + node.reset_physics_interpolation()