summaryrefslogtreecommitdiff
path: root/car.gd
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-06-05 00:36:03 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-06-05 00:36:03 +0200
commit2a81306abc47e94c7ffd5173a031baf36bbfcc24 (patch)
treecf0175a26984e616f762055e2374db73e137849a /car.gd
parent9c918c4a04a656f1017955bcb772ae8ce7c61089 (diff)
downloadcar-2a81306abc47e94c7ffd5173a031baf36bbfcc24.tar.gz
Implement camera and ball
Diffstat (limited to 'car.gd')
-rw-r--r--car.gd41
1 files changed, 31 insertions, 10 deletions
diff --git a/car.gd b/car.gd
index 890fc3a..bbe5872 100644
--- a/car.gd
+++ b/car.gd
@@ -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