2017-02-14 00:54:19 +01:00
|
|
|
|
|
|
|
extends VehicleBody
|
|
|
|
|
|
|
|
# Member variables
|
|
|
|
const STEER_SPEED = .25
|
|
|
|
const STEER_LIMIT = .3
|
|
|
|
|
|
|
|
var steer_angle = 0
|
|
|
|
var steer_target = 0
|
2017-03-21 08:58:06 +01:00
|
|
|
var view_sensitivity = 0.1;
|
2017-02-14 00:54:19 +01:00
|
|
|
|
|
|
|
export var engine_force = 20
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
set_engine_force(-engine_force)
|
|
|
|
|
|
|
|
if (Input.is_action_pressed("driver_break")):
|
|
|
|
set_brake(1.0)
|
|
|
|
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)
|
|
|
|
|
2017-03-21 08:58:06 +01:00
|
|
|
func _enter_tree():
|
|
|
|
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED);
|
2017-02-14 00:54:19 +01:00
|
|
|
|
|
|
|
func _ready():
|
|
|
|
set_fixed_process(true)
|
2017-03-21 08:58:06 +01:00
|
|
|
set_process_input(true)
|
2017-02-14 00:54:19 +01:00
|
|
|
|
|
|
|
func _input(ie):
|
|
|
|
if ie.type == InputEvent.MOUSE_MOTION:
|
2017-03-21 08:58:06 +01:00
|
|
|
var turret = get_node("Turret")
|
|
|
|
var cannon = get_node("Turret/Cannon")
|
|
|
|
#var pitch = rad2deg(camera.get_rotation().x)
|
|
|
|
var plus_pitch = view_sensitivity * -ie.relative_y
|
|
|
|
var plus_yaw = fmod(view_sensitivity * ie.relative_x,360)
|
|
|
|
turret.rotate(Vector3(0,1,0), deg2rad(plus_yaw))
|
|
|
|
cannon.rotate(Vector3(0,0,1), deg2rad(plus_pitch))
|