Skip to content

Instantly share code, notes, and snippets.

@kingthrillgore
Last active March 30, 2023 02:16
Show Gist options
  • Save kingthrillgore/f00ff47b04f9b917ebf25b85266737aa to your computer and use it in GitHub Desktop.
Save kingthrillgore/f00ff47b04f9b917ebf25b85266737aa to your computer and use it in GitHub Desktop.
The original trucktown vehicle code
if Input.is_action_pressed(&"accelerate"):
# Increase engine force at low speeds to make the initial acceleration faster.
var speed := linear_velocity.length()
if speed < 5.0 and not is_zero_approx(speed):
engine_force = clampf(engine_force_value * 5.0 / speed, 0.0, 100.0)
else:
engine_force = engine_force_value
# Apply analog throttle factor for more subtle acceleration if not fully holding down the trigger.
engine_force *= Input.get_action_strength(&"accelerate")
else:
engine_force = 0.0
# Me: easy peasy all I need to do is add a pressed action here to clamp the engine force to 0
# and the brake to 1.0
if Input.is_action_pressed(&"reverse"):
# Increase engine force at low speeds to make the initial acceleration faster.
if fwd_mps >= -1.0:
var speed := linear_velocity.length()
if speed < 5.0 and not is_zero_approx(speed):
engine_force = -clampf(engine_force_value * 5.0 / speed, 0.0, 100.0)
else:
engine_force = -engine_force_value
# Apply analog brake factor for more subtle braking if not fully holding down the trigger.
engine_force *= Input.get_action_strength(&"reverse")
else:
brake = 0.0
else:
brake = 0.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment