diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-06-05 00:36:03 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-06-05 00:36:03 +0200 |
| commit | 2a81306abc47e94c7ffd5173a031baf36bbfcc24 (patch) | |
| tree | cf0175a26984e616f762055e2374db73e137849a /car.gd | |
| parent | 9c918c4a04a656f1017955bcb772ae8ce7c61089 (diff) | |
| download | car-2a81306abc47e94c7ffd5173a031baf36bbfcc24.tar.gz | |
Implement camera and ball
Diffstat (limited to 'car.gd')
| -rw-r--r-- | car.gd | 41 |
1 files changed, 31 insertions, 10 deletions
@@ -1,15 +1,36 @@ extends VehicleBody -var max_rpm = 500 -var max_torque = 200 +var max_rpm = 5000 +var max_torque = 800 func _physics_process(delta): - var new_steering = (Input.get_action_strength("left") - - Input.get_action_strength("right")) * 0.4 - steering = lerp(steering, new_steering, 5 * delta) - var acceleration = (Input.get_action_strength("forward") + var can_jump = false + for w in [$front_left_wheel, $front_right_wheel, + $back_left_wheel, $back_right_wheel]: + if w.is_in_contact(): + can_jump = true + break + + var new_steering = (Input.get_action_strength("left") + - Input.get_action_strength("right")) * 0.4 + var acceleration = (Input.get_action_strength("forward") - Input.get_action_strength("back")) - var rpm = $back_left_wheel.get_rpm() - $back_left_wheel.engine_force = acceleration * max_torque * (1 - rpm / max_rpm) - rpm = $back_right_wheel.get_rpm() - $back_right_wheel.engine_force = acceleration * max_torque * (1 - rpm / max_rpm) + var transform = get_transform().basis + + if can_jump: + steering = lerp(steering, new_steering, 2 * delta) + var rpm = $back_left_wheel.get_rpm() + $back_left_wheel.engine_force = acceleration * max_torque * (1 - rpm / max_rpm) + rpm = $back_right_wheel.get_rpm() + $back_right_wheel.engine_force = acceleration * max_torque * (1 - rpm / max_rpm) + if Input.is_action_just_pressed("jump"): + apply_impulse(Vector3(0, 0, 0), Vector3(0, 2000, 0)) + elif not can_jump: + steering = lerp(steering, 0, 5 * delta) + apply_torque_impulse(10.0 * acceleration * transform.x) + apply_torque_impulse(10.0 * new_steering * transform.y) + +func _ready(): + steering = 0 + $back_left_wheel.engine_force = 0 + $back_right_wheel.engine_force = 0 |
