Files
academy2-game/steering_test.gd
2021-11-01 14:29:07 +03:00

35 lines
747 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)
$Camera.look_at($VehicleBody.global_transform.origin, Vector3.UP)
match state:
0:
$VehicleBody.engine_force = 2000
state = 1
1:
xdel -= delta
if xdel < 0:
$VehicleBody.engine_force = 0