Last active
March 30, 2023 02:16
-
-
Save kingthrillgore/f00ff47b04f9b917ebf25b85266737aa to your computer and use it in GitHub Desktop.
The original trucktown vehicle code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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