fix car reset backwards steering
This commit is contained in:
parent
8871e4663c
commit
23a2e784a9
3 changed files with 36 additions and 9 deletions
|
@ -238,5 +238,9 @@ bus = &"Crash"
|
||||||
stream = SubResource("AudioStreamRandomizer_evs7n")
|
stream = SubResource("AudioStreamRandomizer_evs7n")
|
||||||
bus = &"Crash"
|
bus = &"Crash"
|
||||||
|
|
||||||
|
[node name="NoInputTimer" type="Timer" parent="CharacterBody_Car"]
|
||||||
|
wait_time = 10.0
|
||||||
|
one_shot = true
|
||||||
|
|
||||||
[connection signal="timeout" from="CharacterBody_Car/resetTimer" to="CharacterBody_Car" method="_on_reset_timer_timeout"]
|
[connection signal="timeout" from="CharacterBody_Car/resetTimer" to="CharacterBody_Car" method="_on_reset_timer_timeout"]
|
||||||
[connection signal="timeout" from="CharacterBody_Car/collisionEnableTimer" to="CharacterBody_Car" method="_on_collision_enable_timer_timeout"]
|
[connection signal="timeout" from="CharacterBody_Car/collisionEnableTimer" to="CharacterBody_Car" method="_on_collision_enable_timer_timeout"]
|
||||||
|
|
|
@ -58,7 +58,7 @@ var steering_distance_close_fast=64
|
||||||
var resetcar_stoppedspeed = 50 #activate timer when below this speed
|
var resetcar_stoppedspeed = 50 #activate timer when below this speed
|
||||||
var resetcar_movingspeed=resetcar_stoppedspeed+10 #stop timer when above this speed
|
var resetcar_movingspeed=resetcar_stoppedspeed+10 #stop timer when above this speed
|
||||||
var resetcar_distance=128 #196 is roughly when car is in the middle of a two wide road
|
var resetcar_distance=128 #196 is roughly when car is in the middle of a two wide road
|
||||||
var resetcar_steerangle=120
|
var resetcar_steerangle=120.0/360.0*2*PI
|
||||||
|
|
||||||
# other car avoidance
|
# other car avoidance
|
||||||
var avoid_car_distance_far=100
|
var avoid_car_distance_far=100
|
||||||
|
@ -91,6 +91,7 @@ var burnout:float=0 #at 0 is off
|
||||||
|
|
||||||
|
|
||||||
@onready var reset_timer: Timer = $resetTimer
|
@onready var reset_timer: Timer = $resetTimer
|
||||||
|
@onready var no_input_timer: Timer = $NoInputTimer
|
||||||
|
|
||||||
@onready var ray_cast_car: RayCast2D = $RayCast_Car #for tracking markers
|
@onready var ray_cast_car: RayCast2D = $RayCast_Car #for tracking markers
|
||||||
|
|
||||||
|
@ -128,6 +129,7 @@ func _physics_process(delta: float) -> void:
|
||||||
$Burnout_Left.emitting=false
|
$Burnout_Left.emitting=false
|
||||||
$Burnout_Right.emitting=false
|
$Burnout_Right.emitting=false
|
||||||
|
|
||||||
|
#update_timeout_visibility()
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
|
|
||||||
for i in get_slide_collision_count():
|
for i in get_slide_collision_count():
|
||||||
|
@ -153,8 +155,12 @@ func _physics_process(delta: float) -> void:
|
||||||
if velocity.length() < resetcar_stoppedspeed and autosteer_enabled: #moving slow, possibly crash?
|
if velocity.length() < resetcar_stoppedspeed and autosteer_enabled: #moving slow, possibly crash?
|
||||||
if reset_timer.is_stopped():
|
if reset_timer.is_stopped():
|
||||||
reset_timer.start()
|
reset_timer.start()
|
||||||
|
if no_input_timer.is_stopped():
|
||||||
|
no_input_timer.start()
|
||||||
|
|
||||||
if velocity.length() > resetcar_movingspeed:
|
if velocity.length() > resetcar_movingspeed:
|
||||||
reset_timer.stop()
|
reset_timer.stop()
|
||||||
|
no_input_timer.stop()
|
||||||
|
|
||||||
if running:
|
if running:
|
||||||
enginesound.setCarSpeed(velocity.length())
|
enginesound.setCarSpeed(velocity.length())
|
||||||
|
@ -168,6 +174,18 @@ func _physics_process(delta: float) -> void:
|
||||||
func _on_reset_timer_timeout() -> void:
|
func _on_reset_timer_timeout() -> void:
|
||||||
autoreset=true
|
autoreset=true
|
||||||
|
|
||||||
|
func update_timeout_visibility():
|
||||||
|
var fadeout=1-constrain((3-no_input_timer.time_left)/3.0,0.0,1.0) #1= full visible, 0=timeouted
|
||||||
|
$sprite_body.modulate.a=fadeout
|
||||||
|
$sprite_features.modulate.a=fadeout
|
||||||
|
$sprite_steeringwheel.modulate.a=fadeout
|
||||||
|
|
||||||
|
func getNoInputTimeout():
|
||||||
|
if no_input_timer.time_left<=0:
|
||||||
|
return true
|
||||||
|
else:
|
||||||
|
return false
|
||||||
|
|
||||||
func apply_friction():
|
func apply_friction():
|
||||||
if velocity.length() < STANDSTILLSPEED: #standstill
|
if velocity.length() < STANDSTILLSPEED: #standstill
|
||||||
velocity=Vector2.ZERO
|
velocity=Vector2.ZERO
|
||||||
|
@ -228,7 +246,6 @@ func get_input(delta:float):
|
||||||
steer_direction=1
|
steer_direction=1
|
||||||
'''
|
'''
|
||||||
|
|
||||||
steer_direction+=constrain(steer_direction_aim-steer_direction,max_steering_change*delta,-max_steering_change*delta)
|
|
||||||
|
|
||||||
applied_engine_power=0
|
applied_engine_power=0
|
||||||
|
|
||||||
|
@ -256,19 +273,20 @@ func get_input(delta:float):
|
||||||
|
|
||||||
if autoreset and running:
|
if autoreset and running:
|
||||||
acceleration = transform.x * braking #drive backwards
|
acceleration = transform.x * braking #drive backwards
|
||||||
|
steer_direction_aim=resetcar_steerangle #keep steering to turn around if standing in the middle of a track
|
||||||
if distance_min>=resetcar_distance: #nothing in front of car
|
#steer_direction=steer_direction_aim #steer without smoothing
|
||||||
steer_direction=resetcar_steerangle #keep steering so turn around if standing in the middle of a track
|
|
||||||
else:
|
else:
|
||||||
steer_direction*=-1 #invert steering
|
if steer_direction_aim<0.1:
|
||||||
else:
|
|
||||||
if steer_direction>1:
|
|
||||||
resetcar_steerangle=max(-resetcar_steerangle,+resetcar_steerangle) #calculate steering direction for next autoreset
|
resetcar_steerangle=max(-resetcar_steerangle,+resetcar_steerangle) #calculate steering direction for next autoreset
|
||||||
if steer_direction<1:
|
if steer_direction_aim>0.1:
|
||||||
resetcar_steerangle=min(-resetcar_steerangle,+resetcar_steerangle) #calculate steering direction for next autoreset
|
resetcar_steerangle=min(-resetcar_steerangle,+resetcar_steerangle) #calculate steering direction for next autoreset
|
||||||
|
|
||||||
|
|
||||||
|
steer_direction+=constrain(steer_direction_aim-steer_direction,max_steering_change*delta,-max_steering_change*delta) #smooth steering. towards steer_direction_aim
|
||||||
$sprite_steeringwheel.rotation=steer_direction
|
$sprite_steeringwheel.rotation=steer_direction
|
||||||
|
|
||||||
|
print("steer_direction="+str(steer_direction)+" \t resetcar_steerangle="+str(resetcar_steerangle)+" \t steer_direction_aim="+str(steer_direction_aim))
|
||||||
|
|
||||||
func calculate_steering(delta:float):
|
func calculate_steering(delta:float):
|
||||||
var rear_wheel = position - transform.x *wheel_base/2.0
|
var rear_wheel = position - transform.x *wheel_base/2.0
|
||||||
var front_wheel = position + transform.x *wheel_base/2.0
|
var front_wheel = position + transform.x *wheel_base/2.0
|
||||||
|
|
|
@ -125,6 +125,11 @@ func _process(delta: float) -> void:
|
||||||
if !anyplayerkeypressed and timer_close.is_stopped():
|
if !anyplayerkeypressed and timer_close.is_stopped():
|
||||||
timer_close.start() #start timer when no key is pressed
|
timer_close.start() #start timer when no key is pressed
|
||||||
|
|
||||||
|
func checkCarsTimeout(delta: float):
|
||||||
|
var cars=cars.get_children()
|
||||||
|
for c in cars: #check if any one car is still driving
|
||||||
|
if !c.hasFinished() and c.getNoInputTimeout():
|
||||||
|
print("Removing car")
|
||||||
|
|
||||||
func updateCameraMovement(delta: float):
|
func updateCameraMovement(delta: float):
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue