2014-10-03 03:10:51 +00:00
|
|
|
|
|
|
|
extends VehicleBody
|
|
|
|
|
2015-11-21 12:31:25 +00:00
|
|
|
# Member variables
|
2015-12-09 07:38:23 +00:00
|
|
|
const STEER_SPEED = 1
|
|
|
|
const STEER_LIMIT = 0.4
|
2014-10-03 03:10:51 +00:00
|
|
|
|
2015-12-09 07:38:23 +00:00
|
|
|
var steer_angle = 0
|
|
|
|
var steer_target = 0
|
2014-10-03 03:10:51 +00:00
|
|
|
|
2015-12-09 07:38:23 +00:00
|
|
|
export var engine_force = 40
|
2014-10-03 03:10:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _fixed_process(delta):
|
|
|
|
if (Input.is_action_pressed("ui_left")):
|
2015-12-09 07:38:23 +00:00
|
|
|
steer_target = -STEER_LIMIT
|
2014-10-03 03:10:51 +00:00
|
|
|
elif (Input.is_action_pressed("ui_right")):
|
2015-12-09 07:38:23 +00:00
|
|
|
steer_target = STEER_LIMIT
|
2014-10-03 03:10:51 +00:00
|
|
|
else:
|
2015-12-09 07:38:23 +00:00
|
|
|
steer_target = 0
|
|
|
|
|
2014-10-03 03:10:51 +00:00
|
|
|
if (Input.is_action_pressed("ui_up")):
|
|
|
|
set_engine_force(engine_force)
|
|
|
|
else:
|
|
|
|
set_engine_force(0)
|
2015-12-09 07:38:23 +00:00
|
|
|
|
2014-10-03 03:10:51 +00:00
|
|
|
if (Input.is_action_pressed("ui_down")):
|
|
|
|
set_brake(1)
|
|
|
|
else:
|
|
|
|
set_brake(0.0)
|
2015-12-09 07:38:23 +00:00
|
|
|
|
2014-10-03 03:10:51 +00:00
|
|
|
if (steer_target < steer_angle):
|
|
|
|
steer_angle -= STEER_SPEED*delta
|
|
|
|
if (steer_target > steer_angle):
|
2015-12-09 07:38:23 +00:00
|
|
|
steer_angle = steer_target
|
2014-10-03 03:10:51 +00:00
|
|
|
elif (steer_target > steer_angle):
|
|
|
|
steer_angle += STEER_SPEED*delta
|
|
|
|
if (steer_target < steer_angle):
|
2015-12-09 07:38:23 +00:00
|
|
|
steer_angle = steer_target
|
|
|
|
|
2014-10-03 03:10:51 +00:00
|
|
|
set_steering(steer_angle)
|
2015-12-09 07:38:23 +00:00
|
|
|
|
|
|
|
|
2014-10-03 03:10:51 +00:00
|
|
|
func _ready():
|
|
|
|
set_fixed_process(true)
|