Implement easier steering
parent
2597231387
commit
ba630401b1
|
@ -35,6 +35,7 @@ shape = SubResource( 3 )
|
||||||
[node name="buggy" parent="." instance=ExtResource( 1 )]
|
[node name="buggy" parent="." instance=ExtResource( 1 )]
|
||||||
transform = Transform( 1.00456, 0, 0, 0, 1.00456, 0, 0, 0, 1.00456, -38.0928, 1.38435, -0.0872202 )
|
transform = Transform( 1.00456, 0, 0, 0, 1.00456, 0, 0, 0, 1.00456, -38.0928, 1.38435, -0.0872202 )
|
||||||
mass = 250.0
|
mass = 250.0
|
||||||
|
STEER_SPEED = 1.5
|
||||||
|
|
||||||
[node name="camera" type="Camera" parent="."]
|
[node name="camera" type="Camera" parent="."]
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 5.88022, 23.0639 )
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 5.88022, 23.0639 )
|
||||||
|
|
|
@ -1,11 +1,20 @@
|
||||||
extends VehicleBody
|
extends VehicleBody
|
||||||
|
|
||||||
const STEER_SPEED = 1.5
|
export (float) var MAX_STEER_ANGLE = 25
|
||||||
const STEER_LIMIT = 0.4
|
export (float) var SPEED_STEER_ANGLE = 10
|
||||||
|
export (float) var MAX_STEER_SPEED = 100.0
|
||||||
|
export (float) var MAX_STEER_INPUT = 80.0
|
||||||
|
export (float) var STEER_SPEED = 1.0
|
||||||
|
|
||||||
var steer_target = 0
|
onready var max_steer_angle_rad: float = deg2rad(MAX_STEER_ANGLE)
|
||||||
|
onready var speed_steer_angle_rad: float = deg2rad(SPEED_STEER_ANGLE)
|
||||||
|
onready var max_steer_input_rad: float = deg2rad(MAX_STEER_INPUT)
|
||||||
|
export (Curve) var steer_curve = null
|
||||||
|
|
||||||
export (float) var MAX_ENGINE_FORCE = 100.0
|
var steer_target = 0.0
|
||||||
|
var steer_angle = 0.0
|
||||||
|
|
||||||
|
export (float) var MAX_ENGINE_FORCE = 50.0
|
||||||
export (float) var MAX_BRAKE_FORCE = 50.0
|
export (float) var MAX_BRAKE_FORCE = 50.0
|
||||||
export (float) var THROTTLE_POWER = 10000.0
|
export (float) var THROTTLE_POWER = 10000.0
|
||||||
export (float) var MAX_RPM_LOSS_PS = 3000.0
|
export (float) var MAX_RPM_LOSS_PS = 3000.0
|
||||||
|
@ -16,7 +25,7 @@ export (float) var final_drive = 3.38
|
||||||
export (float) var max_rpm = 7000
|
export (float) var max_rpm = 7000
|
||||||
export (float) var min_rpm = 900
|
export (float) var min_rpm = 900
|
||||||
export (float) var gear_switch_time = 0.2
|
export (float) var gear_switch_time = 0.2
|
||||||
export (Curve) var power_curve
|
export (Curve) var power_curve = null
|
||||||
|
|
||||||
var clutch_position: float = 0.0
|
var clutch_position: float = 0.0
|
||||||
var rpm = 0
|
var rpm = 0
|
||||||
|
@ -104,9 +113,19 @@ func _physics_process(delta: float):
|
||||||
rrwheel.brake = handbrake * MAX_BRAKE_FORCE / 2
|
rrwheel.brake = handbrake * MAX_BRAKE_FORCE / 2
|
||||||
rlwheel.brake = handbrake * MAX_BRAKE_FORCE / 2
|
rlwheel.brake = handbrake * MAX_BRAKE_FORCE / 2
|
||||||
|
|
||||||
$Info.text = "Gear: %d, RPM: %.0f, TRPM: %.0f, Engine force: %.0f" % [ gear, rpm, transmission_rpm, engine_force ]
|
var speed = wheel_rpm * 2.0 * PI * rrwheel.wheel_radius / 60.0 * 3600.0 / 1000.0
|
||||||
|
$Info.text = "Gear: %d, KPH: %.0f, RPM: %.0f, TRPM: %.0f, Engine force: %.0f" % [ gear, speed, rpm, transmission_rpm, engine_force ]
|
||||||
|
|
||||||
steer_target = Input.get_action_strength("steer_left") - Input.get_action_strength("steer_right")
|
var steering_input = Input.get_action_strength("steer_left") - Input.get_action_strength("steer_right")
|
||||||
steer_target *= STEER_LIMIT
|
if abs(steering_input) < 0.05:
|
||||||
|
steering_input = 0.0
|
||||||
|
elif steer_curve:
|
||||||
|
if steering_input < 0.0:
|
||||||
|
steering_input = -steer_curve.interpolate_baked(-steering_input)
|
||||||
|
else:
|
||||||
|
steering_input = steer_curve.interpolate_baked(steering_input)
|
||||||
|
|
||||||
steering = move_toward(steering, steer_target, STEER_SPEED * delta)
|
var steer_speed_factor = clamp(speed / MAX_STEER_SPEED, 0.0, 1.0)
|
||||||
|
|
||||||
|
steer_angle = steering_input * lerp(max_steer_angle_rad, speed_steer_angle_rad, steer_speed_factor)
|
||||||
|
steering = steer_angle
|
||||||
|
|
|
@ -11,6 +11,7 @@ extents = Vector3( 0.521885, 0.334919, 1.78849 )
|
||||||
|
|
||||||
[node name="buggy" instance=ExtResource( 1 )]
|
[node name="buggy" instance=ExtResource( 1 )]
|
||||||
script = ExtResource( 3 )
|
script = ExtResource( 3 )
|
||||||
|
STEER_SPEED = 1.5
|
||||||
power_curve = SubResource( 2 )
|
power_curve = SubResource( 2 )
|
||||||
|
|
||||||
[node name="chassis" parent="." index="0"]
|
[node name="chassis" parent="." index="0"]
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
data = PoolVector3Array( -1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, -1, 1, -1, -1, 1, 1, 1, -1, -1, 1, -1, 1, -1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, 1, 1, 1, 1, -1, 1, -1, 1, 1, 1, -1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1, 1, 1, -1, -1, -1, -1, 1, 1, -1, -1, 1, -1, -1, -1, 1, 1, 1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1, -1, 1, 1, -1, -1, -1, 1, 1, -1, 1, -1, -1, -1, 1, -1, 1, 1, -1, -1, -1, -1, -1 )
|
data = PoolVector3Array( -1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, -1, 1, -1, -1, 1, 1, 1, -1, -1, 1, -1, 1, -1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, 1, 1, 1, 1, -1, 1, -1, 1, 1, 1, -1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1, 1, 1, -1, -1, -1, -1, 1, 1, -1, -1, 1, -1, -1, -1, 1, 1, 1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1, -1, 1, 1, -1, -1, -1, 1, 1, -1, 1, -1, -1, -1, 1, -1, 1, 1, -1, -1, -1, -1, -1 )
|
||||||
|
|
||||||
[node name="buggy" instance=ExtResource( 1 )]
|
[node name="buggy" instance=ExtResource( 1 )]
|
||||||
|
STEER_SPEED = 1.5
|
||||||
|
|
||||||
[node name="Camera" type="Camera" parent="." index="7"]
|
[node name="Camera" type="Camera" parent="." index="7"]
|
||||||
transform = Transform( -0.0903024, 0, -0.995914, 0, 1, 0, 0.995914, 0, -0.0903024, -3.4904, 1.22508, 0 )
|
transform = Transform( -0.0903024, 0, -0.995914, 0, 1, 0, 0.995914, 0, -0.0903024, -3.4904, 1.22508, 0 )
|
||||||
|
|
Loading…
Reference in New Issue