player inputs on boat

This commit is contained in:
Lucas 2025-03-25 18:23:14 +01:00
parent 6026ceb1cf
commit 0b1abe8fda
No known key found for this signature in database
23 changed files with 491 additions and 19 deletions

2
.gitattributes vendored
View file

@ -1,3 +1,5 @@
# Normalize EOL for all files that Git considers text files.
* text=auto eol=lf
*.psd filter=lfs diff=lfs merge=lfs -text
*.fbx filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text

View file

@ -2,14 +2,54 @@
extends RigidBody3D
class_name Boat
@export var max_thrust_force: float = 2048*3.0
@export var max_steering: float = 50.0
var steering: float = 0 # steering rudder angle in radians
var thrust_force: float = 0 # forward thrust force in Newtons
var cam_rotation:Vector3
var is_docked: bool = false
var submerged := false
func _ready():
add_to_group("boats",true)
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
func _physics_process(delta):
## Code for user-input movement
if thrust_force >0.0:
apply_central_force(self.global_transform.basis.x.normalized() * Vector3(1, 0, 1) * thrust_force * delta)
#apply_torque(Vector3.UP * steering * delta)
apply_torque(global_transform.basis.y.normalized() * steering ) # for sideways motion
reset_forces()
func _process(_delta):
if Input.get_action_strength("move_forward") > 0.0:
thrust()
if Input.get_action_strength("turn_right") > 0.0:
steer_right()
if Input.get_action_strength("turn_left") > 0.0:
steer_left()
if Input.get_action_strength("camera_left") > 0.0:
cam_rotation += Vector3(0.0,1.0,0.0)*_delta
if Input.get_action_strength("camera_right") > 0.0:
cam_rotation += Vector3(0.0,-1.0,0.0)*_delta
func thrust(_strength:=1.0):
if not is_docked:
thrust_force = max_thrust_force
func steer_right(_strength:=1.0):
if not is_docked:
steering = -PI * max_steering
func steer_left(_strength:=1.0):
if not is_docked:
steering = PI * max_steering
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
pass
func reset_forces():
thrust_force = 0
steering = 0

67
Boats/boat.tscn Normal file
View file

@ -0,0 +1,67 @@
[gd_scene load_steps=6 format=3 uid="uid://bdfqifxsvpts4"]
[ext_resource type="Script" uid="uid://cjo6l2ykgvn4e" path="res://Boats/boat.gd" id="1_q76at"]
[ext_resource type="PackedScene" uid="uid://bu6chp8qribgy" path="res://Boats/cartoon-boat/source/boat 4.fbx" id="2_bmmu8"]
[ext_resource type="Script" uid="uid://cnfkxclrq0i0s" path="res://Boats/buyancy_probe.gd" id="3_dd4jx"]
[sub_resource type="GDScript" id="GDScript_dd4jx"]
script/source = "extends Node3D
func _process(_delta):
pass
#global_rotation = $\"../..\".cam_rotation
"
[sub_resource type="BoxShape3D" id="BoxShape3D_g5njt"]
size = Vector3(5.26923, 1, 3.88843)
[node name="Boat" type="RigidBody3D"]
mass = 50.0
script = ExtResource("1_q76at")
max_thrust_force = 3000.0
max_steering = 150.0
metadata/_custom_type_script = "uid://cjo6l2ykgvn4e"
[node name="boat 4" parent="." instance=ExtResource("2_bmmu8")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -4.8577)
[node name="CamRoot" type="Node3D" parent="boat 4"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.02675, 1.50566, 4.94378)
script = SubResource("GDScript_dd4jx")
[node name="SpringArm3D" type="SpringArm3D" parent="boat 4/CamRoot"]
transform = Transform3D(0.489698, 0.510696, -0.706672, -0.000524942, 0.810677, 0.585494, 0.871892, -0.286344, 0.397255, 0, 0, 0)
collision_mask = 0
spring_length = 10.0
[node name="Camera3D" type="Camera3D" parent="boat 4/CamRoot/SpringArm3D"]
transform = Transform3D(1, 0, 5.96046e-08, 0, 1, -1.04308e-07, 0, 2.98023e-08, 1, 1.78167, 1.43974, 8.17264)
current = true
[node name="BuyancyProbe" type="Marker3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.15306, 1.02582, 1.3511)
script = ExtResource("3_dd4jx")
show_probe = true
metadata/_custom_type_script = "uid://cnfkxclrq0i0s"
[node name="BuyancyProbe2" type="Marker3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.933215, 1.32675, -1.50793)
script = ExtResource("3_dd4jx")
show_probe = true
metadata/_custom_type_script = "uid://cnfkxclrq0i0s"
[node name="BuyancyProbe3" type="Marker3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2.95977, 1.07616, 1.18863)
script = ExtResource("3_dd4jx")
show_probe = true
metadata/_custom_type_script = "uid://cnfkxclrq0i0s"
[node name="BuyancyProbe4" type="Marker3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2.95977, 0.847872, -0.88629)
script = ExtResource("3_dd4jx")
show_probe = true
metadata/_custom_type_script = "uid://cnfkxclrq0i0s"
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.789459, 1.27738, 0)
shape = SubResource("BoxShape3D_g5njt")

View file

@ -64,9 +64,10 @@ func _process(_delta: float) -> void:
func get_wave_height(world_position: Vector3, time: float) -> float:
var uv_x = wrapf(world_position.x / noise_scale + time * wave_speed, 0, 1)
var uv_y = wrapf(world_position.z / noise_scale + time * wave_speed, 0, 1)
if noise != null:
var pixel_pos = Vector2(uv_x * noise.get_width(), uv_y * noise.get_height())
return OceanNode.global_position.y + noise.get_pixelv(pixel_pos).r * height_scale;
return world_position.y
func update_param():
if ocean_mat != null:

BIN
Boats/cartoon-boat/source/boat 4.fbx (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -0,0 +1,50 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://bu6chp8qribgy"
path="res://.godot/imported/boat 4.fbx-4f459f3d14e15dbdd6449d0939ad6231.scn"
[deps]
source_file="res://Boats/cartoon-boat/source/boat 4.fbx"
dest_files=["res://.godot/imported/boat 4.fbx-4f459f3d14e15dbdd6449d0939ad6231.scn"]
[params]
nodes/root_type=""
nodes/root_name=""
nodes/apply_root_scale=true
nodes/root_scale=1.0
nodes/import_as_skeleton_bones=false
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=true
animation/remove_immutable_tracks=true
animation/import_rest_as_RESET=false
import_script/path=""
_subresources={
"materials": {
"lambert1": {
"use_external/enabled": true,
"use_external/path": "uid://b0r2c7455ns2l"
}
},
"nodes": {
"PATH:AnimationPlayer": {
"import/skip_import": true
}
}
}
fbx/importer=0
fbx/allow_geometry_helper_nodes=false
fbx/embedded_image_handling=1

View file

@ -0,0 +1,61 @@
[gd_resource type="VisualShader" load_steps=9 format=3 uid="uid://5is85o5k05lb"]
[ext_resource type="Texture2D" uid="uid://b3htar5wp3ag2" path="res://Boats/cartoon-boat/textures/boat_4_lambert1_BaseColor.png" id="1_igkxg"]
[ext_resource type="Texture2D" uid="uid://conebiij3gpe8" path="res://Boats/cartoon-boat/textures/boat_4_lambert1_Metalness.png" id="2_c0qec"]
[ext_resource type="Texture2D" uid="uid://cqu3udiqdiw5u" path="res://Boats/cartoon-boat/textures/boat_4_lambert1_Normal.png" id="3_ygw4n"]
[ext_resource type="Texture2D" uid="uid://brltubuleyx6p" path="res://Boats/cartoon-boat/textures/boat_4_lambert1_Roughness.png" id="4_yj6bl"]
[sub_resource type="VisualShaderNodeTexture" id="VisualShaderNodeTexture_v2np7"]
texture = ExtResource("1_igkxg")
[sub_resource type="VisualShaderNodeTexture" id="VisualShaderNodeTexture_y2thm"]
texture = ExtResource("2_c0qec")
[sub_resource type="VisualShaderNodeTexture" id="VisualShaderNodeTexture_2d07w"]
texture = ExtResource("3_ygw4n")
[sub_resource type="VisualShaderNodeTexture" id="VisualShaderNodeTexture_fban5"]
texture = ExtResource("4_yj6bl")
[resource]
code = "shader_type spatial;
render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_toon, specular_toon;
uniform sampler2D tex_frg_2;
uniform sampler2D tex_frg_5;
uniform sampler2D tex_frg_4;
void fragment() {
// Texture2D:2
vec4 n_out2p0 = texture(tex_frg_2, UV);
// Texture2D:5
vec4 n_out5p0 = texture(tex_frg_5, UV);
// Texture2D:4
vec4 n_out4p0 = texture(tex_frg_4, UV);
// Output:0
ALBEDO = vec3(n_out2p0.xyz);
ROUGHNESS = n_out5p0.x;
NORMAL = vec3(n_out4p0.xyz);
}
"
modes/diffuse = 3
modes/specular = 1
nodes/fragment/2/node = SubResource("VisualShaderNodeTexture_v2np7")
nodes/fragment/2/position = Vector2(40, 20)
nodes/fragment/3/node = SubResource("VisualShaderNodeTexture_y2thm")
nodes/fragment/3/position = Vector2(-40, 360)
nodes/fragment/4/node = SubResource("VisualShaderNodeTexture_2d07w")
nodes/fragment/4/position = Vector2(-40, 680)
nodes/fragment/5/node = SubResource("VisualShaderNodeTexture_fban5")
nodes/fragment/5/position = Vector2(-400, 440)
nodes/fragment/connections = PackedInt32Array(2, 0, 0, 0, 5, 0, 0, 3, 4, 0, 0, 8)

View file

@ -0,0 +1,7 @@
[gd_resource type="ShaderMaterial" load_steps=2 format=3 uid="uid://b0r2c7455ns2l"]
[ext_resource type="Shader" uid="uid://5is85o5k05lb" path="res://Boats/cartoon-boat/textures/boat.tres" id="1_ydsd6"]
[resource]
render_priority = 0
shader = ExtResource("1_ydsd6")

BIN
Boats/cartoon-boat/textures/boat_4_lambert1_BaseColor.png (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://b3htar5wp3ag2"
path.s3tc="res://.godot/imported/boat_4_lambert1_BaseColor.png-c115378871e9c14ec1968c2847d8cb2a.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://Boats/cartoon-boat/textures/boat_4_lambert1_BaseColor.png"
dest_files=["res://.godot/imported/boat_4_lambert1_BaseColor.png-c115378871e9c14ec1968c2847d8cb2a.s3tc.ctex"]
[params]
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=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
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

BIN
Boats/cartoon-boat/textures/boat_4_lambert1_Metalness.png (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://conebiij3gpe8"
path.s3tc="res://.godot/imported/boat_4_lambert1_Metalness.png-b09edd3d302acb8e51ce4c4cff9fe7de.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://Boats/cartoon-boat/textures/boat_4_lambert1_Metalness.png"
dest_files=["res://.godot/imported/boat_4_lambert1_Metalness.png-b09edd3d302acb8e51ce4c4cff9fe7de.s3tc.ctex"]
[params]
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=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
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

BIN
Boats/cartoon-boat/textures/boat_4_lambert1_Normal.png (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cqu3udiqdiw5u"
path.s3tc="res://.godot/imported/boat_4_lambert1_Normal.png-f950f375cb3203315d9984306087da8f.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://Boats/cartoon-boat/textures/boat_4_lambert1_Normal.png"
dest_files=["res://.godot/imported/boat_4_lambert1_Normal.png-f950f375cb3203315d9984306087da8f.s3tc.ctex"]
[params]
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=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
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

BIN
Boats/cartoon-boat/textures/boat_4_lambert1_Roughness.png (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://brltubuleyx6p"
path.s3tc="res://.godot/imported/boat_4_lambert1_Roughness.png-47634d56a8d31c3aeafe4adb7842f89b.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://Boats/cartoon-boat/textures/boat_4_lambert1_Roughness.png"
dest_files=["res://.godot/imported/boat_4_lambert1_Roughness.png-47634d56a8d31c3aeafe4adb7842f89b.s3tc.ctex"]
[params]
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=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
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

BIN
Boats/wooden-boat/source/untitled.fbx (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -0,0 +1,38 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://dnxg7m7qb17m2"
path="res://.godot/imported/untitled.fbx-885fefb9c878ef12b4480941c30cc4bf.scn"
[deps]
source_file="res://Boats/wooden-boat/source/untitled.fbx"
dest_files=["res://.godot/imported/untitled.fbx-885fefb9c878ef12b4480941c30cc4bf.scn"]
[params]
nodes/root_type=""
nodes/root_name=""
nodes/apply_root_scale=true
nodes/root_scale=1.0
nodes/import_as_skeleton_bones=false
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=true
animation/remove_immutable_tracks=true
animation/import_rest_as_RESET=false
import_script/path=""
_subresources={}
fbx/importer=0
fbx/allow_geometry_helper_nodes=false
fbx/embedded_image_handling=1

BIN
Boats/wooden-boat/textures/Untitled.png (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://lsn1rdgt1ahf"
path.s3tc="res://.godot/imported/Untitled.png-256d0bdd70e310aad901568479012ae9.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://Boats/wooden-boat/textures/Untitled.png"
dest_files=["res://.godot/imported/Untitled.png-256d0bdd70e310aad901568479012ae9.s3tc.ctex"]
[params]
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=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
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

View file

@ -49,10 +49,12 @@ shader_parameter/shore_fade = 0.165
shader_parameter/shore_intensity = 0.7
shader_parameter/metallic = 0.0
shader_parameter/roughness = 0.02
shader_parameter/water_alpha_fade = 4.407
shader_parameter/water_alpha_max = 3.791
shader_parameter/texture_normal = SubResource("NoiseTexture2D_d50os")
shader_parameter/texture_normal2 = SubResource("NoiseTexture2D_ca8p6")
shader_parameter/wave = SubResource("NoiseTexture2D_cuet1")
shader_parameter/wave_time = 46.1837
shader_parameter/wave_time = 82.8805
shader_parameter/wave_direction = Vector2(2, 0)
shader_parameter/wave_2_direction = Vector2(0, 0.9)
shader_parameter/time_scale = 0.02

View file

@ -12,6 +12,8 @@ uniform float shore_fade = 1.0;
uniform float shore_intensity = 1.0;
uniform float metallic : hint_range(0.0, 1.0) = 0;
uniform float roughness : hint_range(0.0, 1.0) = 0.02;
uniform float water_alpha_fade : hint_range(0.0, 5.0) = 1.0;
uniform float water_alpha_max : hint_range(0.001, 15.0) = 1.0;
uniform sampler2D texture_normal;
uniform sampler2D texture_normal2;
@ -80,9 +82,17 @@ void fragment() {
float fresnel = fresnel(5.0, NORMAL, VIEW);
vec3 surface_color = mix(albedo, albedo2, fresnel);
vec3 depth_color_adj = mix(edge_color, color, step(edge_scale, z_dif));
// Compute the world-space position from the depth texture as before.
vec4 alpha_depth_world_pos = INV_PROJECTION_MATRIX * vec4(SCREEN_UV * 2.0 - 1.0, texture(DEPTH_TEXTURE, SCREEN_UV).r, 1.0);
alpha_depth_world_pos.xyz /= alpha_depth_world_pos.w;
// Calculate water_alpha based on how far VERTEX.z is from the depth sample.
float water_alpha = clamp(1.0 - smoothstep(clamp(alpha_depth_world_pos.z + water_alpha_fade,0.0,water_alpha_max+alpha_depth_world_pos.z), alpha_depth_world_pos.z, VERTEX.y), 0.0, 1.0) ;
ALBEDO = clamp(surface_color + depth_color_adj + shore_color * shore_intensity,vec3(0),vec3(1.0));
ALPHA = 1.0;
ALPHA = water_alpha;
METALLIC = metallic;
ROUGHNESS = roughness;
NORMAL_MAP = normal_blend;

View file

@ -6,7 +6,7 @@
[ext_resource type="PlaneMesh" uid="uid://c82xwqk7ljku0" path="res://Ocean/OceanTile_PlaneMesh_Far.tres" id="3_spien"]
[ext_resource type="Script" uid="uid://cnfkxclrq0i0s" path="res://Boats/buyancy_probe.gd" id="5_spien"]
[ext_resource type="Script" uid="uid://3ympc26kcuul" path="res://Ocean/WeatherManager.gd" id="6_kisq7"]
[ext_resource type="Script" uid="uid://cjo6l2ykgvn4e" path="res://Boats/boat.gd" id="7_0g14k"]
[ext_resource type="PackedScene" uid="uid://bdfqifxsvpts4" path="res://Boats/boat.tscn" id="7_0g14k"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_xncsh"]
sky_top_color = Color(0.191699, 0.357914, 1, 1)
@ -26,6 +26,7 @@ sdfgi_enabled = true
glow_enabled = true
fog_enabled = true
fog_sky_affect = 0.699
volumetric_fog_enabled = true
[sub_resource type="BoxMesh" id="BoxMesh_spien"]
size = Vector3(5, 0.2, 5)
@ -40,6 +41,7 @@ size = Vector3(0.3, 0.8, 0.3)
size = Vector3(0.3, 0.8, 0.3)
[node name="OpenWorld" type="Node3D"]
metadata/_edit_lock_ = true
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_q57bq")
@ -48,6 +50,7 @@ environment = SubResource("Environment_q57bq")
transform = Transform3D(-0.149535, -0.420992, 0.894653, 0, 0.904827, 0.425779, -0.988756, 0.0636691, -0.135304, 0, 1.45796, 0)
light_color = Color(0.969986, 0.876638, 0.798898, 1)
shadow_enabled = true
metadata/_edit_lock_ = true
[node name="Ocean" type="Node3D" parent="." groups=["Ocean"]]
script = ExtResource("1_xncsh")
@ -631,13 +634,8 @@ float_strength = 2.0
show_probe = true
metadata/_custom_type_script = "uid://cnfkxclrq0i0s"
[node name="DebugCamera3D" type="Camera3D" parent="."]
transform = Transform3D(0.817859, -0.4492, 0.35962, 0, 0.62497, 0.780649, -0.575419, -0.63846, 0.511137, 8.74584, 11.0902, 11.4458)
current = true
[node name="WeatherManager" type="Node" parent="."]
script = ExtResource("6_kisq7")
[node name="Boat" type="RigidBody3D" parent="."]
script = ExtResource("7_0g14k")
metadata/_custom_type_script = "uid://cjo6l2ykgvn4e"
[node name="Boat" parent="." instance=ExtResource("7_0g14k")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -6.13393, 0, -0.448954)