virtualx-engine/demos/3d/truck_town/vehicle.gd
Rémi Verschelde 8639cecf4c Improve code formatting and update to 2.0
The scripts were streamlined using more or less the following conventions:
 - space after a comma in lists of arguments
 - space around weak operators (+, -), no space around strong operators (*, /)
 - space after a comment start (#)
 - removed trailing spaces or tabs, apart from those that delimit the function indentation level (those could be removed too but since they are added automatically by the editor when typing code, keeping them for now)
 - function blocks separate by two newlines

The scene files were resaved with the (current) 2.0 format, and some scenes that were in XML format were converted to SCN, to be consistent across all demos.
2015-12-09 08:38:23 +01:00

46 lines
913 B
GDScript

extends VehicleBody
# member variables
const STEER_SPEED = 1
const STEER_LIMIT = 0.4
var steer_angle = 0
var steer_target = 0
export var engine_force = 40
func _fixed_process(delta):
if (Input.is_action_pressed("ui_left")):
steer_target = -STEER_LIMIT
elif (Input.is_action_pressed("ui_right")):
steer_target = STEER_LIMIT
else:
steer_target = 0
if (Input.is_action_pressed("ui_up")):
set_engine_force(engine_force)
else:
set_engine_force(0)
if (Input.is_action_pressed("ui_down")):
set_brake(1)
else:
set_brake(0.0)
if (steer_target < steer_angle):
steer_angle -= STEER_SPEED*delta
if (steer_target > steer_angle):
steer_angle = steer_target
elif (steer_target > steer_angle):
steer_angle += STEER_SPEED*delta
if (steer_target < steer_angle):
steer_angle = steer_target
set_steering(steer_angle)
func _ready():
# Initalization here
set_fixed_process(true)