Skip to content

Commit

Permalink
Improved resetting cars
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtyIF committed Dec 6, 2024
1 parent 7b21911 commit 2f68f36
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
42 changes: 42 additions & 0 deletions addons/aacc/scripts/car.gd
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,48 @@ func _ready():
if wheel is CarWheel:
wheels.append(wheel)

## Resets every dynamically-updated value to their initial value. Exported
## values that are user-editable are not affected.
func reset() -> void:
#== INPUT ==#
input_forward = 0.0
input_backward = 0.0
input_steer = 0.0
input_handbrake = false
old_input_handbrake = false

#== VELOCITIES ==#
local_linear_velocity = Vector3.ZERO
local_angular_velocity = Vector3.ZERO
old_linear_velocity = Vector3.ZERO
old_angular_velocity = Vector3.ZERO

#== GROUND ==#
ground_coefficient = 1.0
average_wheel_collision_point = Vector3.ZERO
average_wheel_collision_normal = Vector3.ZERO

#== SMOOTH VALUES ==#
smooth_steer = SmoothedFloat.new()
smooth_steer_sign = SmoothedFloat.new()
use_smooth_steer_sign_value = false

#== GEARS ==#
current_gear = 0
target_gear = 0
switching_gears = false
gear_switch_timer = 0.0
revs = SmoothedFloat.new()
accel_amount = SmoothedFloat.new(0.0, 60.0)

#== BURNOUT AMOUNT ==#
burnout_amount = 0.0

#== WHEELS ==#
for wheel in wheels:
wheel.reset()


#region Processing
func get_input_steer_multiplier() -> float:
if local_linear_velocity.z > 0.0: return 1.0
Expand Down
21 changes: 18 additions & 3 deletions addons/aacc/scripts/car_wheel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ var current_forward_spin: float = 0.0

#== EXTERNAL ==#
var is_colliding: bool = false
var collision_point: Vector3
var collision_normal: Vector3
var distance: float
var collision_point: Vector3 = Vector3.ZERO
var collision_normal: Vector3 = Vector3.ZERO
var distance: float = 0.0

func _ready() -> void:
# TODO: use ShapeCast3D instead
Expand All @@ -70,6 +70,21 @@ func _ready() -> void:
# to make the wheels execute slightly before the car.
process_physics_priority = -1

func reset() -> void:
#== COMPRESSION ==#
compression = 0.0
last_compression = 0.0
last_compression_set = false

#== VISUALS ==#
current_forward_spin = 0.0

#== EXTERNAL ==#
is_colliding = false
collision_point = Vector3.ZERO
collision_normal = Vector3.ZERO
distance = 0.0

func configure_raycasts() -> void:
raycast_instance_1.target_position = (Vector3.DOWN * (wheel_radius + suspension_length))
raycast_instance_1.enabled = true
Expand Down
1 change: 1 addition & 0 deletions demo_assets/scripts/car_resetter.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ func _physics_process(_delta: float) -> void:
_car.angular_velocity = Vector3.ZERO
_car.force_update_transform()
_car.reset_physics_interpolation()
_car.reset()

0 comments on commit 2f68f36

Please sign in to comment.