Skip to content

Commit e691f98

Browse files
authored
Merge pull request #302 from kkmzero/patch-1
Automatic brake/reverse
2 parents 99f6e67 + bded14a commit e691f98

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

3d/truck_town/vehicle.gd

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ var steer_target = 0
1010
export var engine_force_value = 40
1111

1212
func _physics_process(delta):
13+
var fwd_mps = transform.basis.xform_inv(linear_velocity).x
14+
1315
if Input.is_action_pressed("ui_left"):
1416
steer_target = STEER_LIMIT
1517
elif Input.is_action_pressed("ui_right"):
@@ -23,7 +25,10 @@ func _physics_process(delta):
2325
engine_force = 0
2426

2527
if Input.is_action_pressed("ui_down"):
26-
brake = 1
28+
if (fwd_mps >= -1):
29+
engine_force = -engine_force_value
30+
else:
31+
brake = 1
2732
else:
2833
brake = 0.0
2934

0 commit comments

Comments
 (0)