36 lines
814 B
GDScript3
36 lines
814 B
GDScript3
extends Spatial
|
|
|
|
|
|
# Declare member variables here. Examples:
|
|
# var a = 2
|
|
# var b = "text"
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
pass # Replace with function body.
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
var xdel = 16.0
|
|
var state = 0
|
|
func _process(delta):
|
|
var tgt = $target.global_transform.origin
|
|
var xt = $VehicleBody.global_transform.affine_inverse()
|
|
var loc = xt.xform(tgt)
|
|
$VehicleBody.steering = clamp(loc.x, -1, 1)
|
|
print(loc.x, " ", loc.z, $VehicleBody.linear_velocity)
|
|
$Camera.look_at($VehicleBody.global_transform.origin, Vector3.UP)
|
|
print($VehicleBody.linear_velocity)
|
|
match state:
|
|
0:
|
|
$VehicleBody.engine_force = 2000
|
|
state = 1
|
|
1:
|
|
xdel -= delta
|
|
if xdel < 0:
|
|
$VehicleBody.engine_force = 0
|
|
|
|
|
|
|