player controller logic
This commit is contained in:
+3
-12
@@ -1,27 +1,19 @@
|
||||
class_name Boat
|
||||
extends FloatingBody
|
||||
|
||||
## All force values are per-kilogram (they get multiplied by mass), so the
|
||||
## boat handles the same if you change its mass later.
|
||||
## All values multiplied by mass, handling the same regardless of it
|
||||
@export var engine_power := 12.0 # forward thrust, m/s² at full throttle
|
||||
@export var reverse_ratio := 0.4 # reverse is weaker, like a real prop
|
||||
@export var throttle_response := 1.5 # how fast the engine spools up/down
|
||||
@export var rudder_strength := 2.5 # turning torque at speed
|
||||
@export var keel_grip := 3.0 # resistance to sliding sideways
|
||||
|
||||
var desired_throttle := 0.0
|
||||
var desired_throttle := 0.0 # move_toward target for actual throttle
|
||||
var steer_input := 0.0
|
||||
var throttle := 0.0
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
super(delta)
|
||||
|
||||
if Input.is_action_pressed("throttle_increase"):
|
||||
desired_throttle = move_toward(desired_throttle, 1, 0.005)
|
||||
elif Input.is_action_pressed("throttle_decrease"):
|
||||
desired_throttle = move_toward(desired_throttle, -1, 0.006)
|
||||
elif Input.is_action_pressed("throttle_stop"):
|
||||
desired_throttle = 0.0
|
||||
|
||||
throttle = move_toward(throttle, desired_throttle, throttle_response * delta)
|
||||
|
||||
@@ -38,7 +30,6 @@ func _physics_process(delta: float) -> void:
|
||||
apply_central_force(forward * throttle * power * mass * submerged_ratio)
|
||||
|
||||
# --- rudder: only bites when water flows past it ---
|
||||
var steer_input := Input.get_axis("rudder_right", "rudder_left")
|
||||
var forward_speed := linear_velocity.dot(forward)
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user