Boat/Boats/boat.gd
LUCASTUCIOUS 31ac4db49e A lot of changes
- Changed the scale of the project. Since water tiles are 10m, a boat need to occupy less than 1/3 of the space. So i made a 2m long boat. We'll see.
- Removed corrupted fbx. Hail for the bite
- Removed buyancy probe view. @TODO: make a CheatCode manager to help debug
- Made the ocean follow you
-
2025-03-27 00:03:49 +01:00

59 lines
1.6 KiB
GDScript

@icon("uid://3ugrjpybrl4e")
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)
func _process(_delta):
if Input.get_action_strength("move_forward") > 0.0:
thrust(Input.get_action_strength("move_forward"))
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
$CamRoot.global_rotation = cam_rotation
$CamRoot.global_position.y = 0.0
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 * clamp(Input.get_action_strength("move_forward"),0.35,1.0) ) # for sideways motion
reset_forces()
func thrust(_strength:=1.0):
if not is_docked:
thrust_force = max_thrust_force * _strength
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
func reset_forces():
thrust_force = 0
steering = 0