Boat/boat/boat.gd
2025-03-21 17:43:59 +01:00

40 lines
1 KiB
GDScript

extends RigidBody3D
@export var float_force := 40
@export var water_drag := 0.05
@export var water_angular_drag := 0.05
@onready var gravity:float = ProjectSettings.get_setting("physics/3d/default_gravity")
const upforce_max := 500.0
const water_height :=0.0
var inWater := false
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func _physics_process(_delta: float) -> void:
var currentDepth = water_height - global_position.y
if currentDepth > 0:
inWater = true
var force_to_apply:Vector3 = Vector3.UP * clamp(float_force * gravity * currentDepth,0.0,upforce_max)
apply_central_force(force_to_apply)
else:
inWater = false
func _integrate_forces(state: PhysicsDirectBodyState3D) -> void:
# Change comportement based on if in water or not
if inWater:
state.linear_velocity *= 1 - water_drag
state.angular_velocity *= 1 - water_angular_drag