Added steering test

This commit is contained in:
Segey Lapin
2021-11-01 14:28:32 +03:00
parent daece19b55
commit aae5d0a8c3
2 changed files with 168 additions and 0 deletions

34
steering_test.gd Normal file
View File

@@ -0,0 +1,34 @@
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

134
steering_test.tscn Normal file
View File

@@ -0,0 +1,134 @@
[gd_scene load_steps=12 format=2]
[ext_resource path="res://steering_test.gd" type="Script" id=1]
[sub_resource type="SphereMesh" id=3]
radius = 0.2
[sub_resource type="CubeMesh" id=1]
[sub_resource type="CubeMesh" id=2]
size = Vector3( 2, 1, 4 )
[sub_resource type="BoxShape" id=4]
extents = Vector3( 1, 1, 2.00042 )
[sub_resource type="SphereMesh" id=5]
radius = 0.5
height = 1.0
[sub_resource type="SphereMesh" id=6]
radius = 0.5
height = 1.0
[sub_resource type="ProceduralSky" id=9]
[sub_resource type="Environment" id=10]
background_mode = 2
background_sky = SubResource( 9 )
[sub_resource type="PlaneMesh" id=7]
size = Vector2( 40, 40 )
subdivide_width = 5
subdivide_depth = 5
[sub_resource type="ConcavePolygonShape" id=8]
data = PoolVector3Array( 20, 0, 20, 13.3333, 0, 20, 20, 0, 13.3333, 13.3333, 0, 20, 13.3333, 0, 13.3333, 20, 0, 13.3333, 13.3333, 0, 20, 6.6667, 0, 20, 13.3333, 0, 13.3333, 6.6667, 0, 20, 6.6667, 0, 13.3333, 13.3333, 0, 13.3333, 6.6667, 0, 20, 0, 0, 20, 6.6667, 0, 13.3333, 0, 0, 20, 0, 0, 13.3333, 6.6667, 0, 13.3333, 0, 0, 20, -6.6667, 0, 20, 0, 0, 13.3333, -6.6667, 0, 20, -6.6667, 0, 13.3333, 0, 0, 13.3333, -6.6667, 0, 20, -13.3333, 0, 20, -6.6667, 0, 13.3333, -13.3333, 0, 20, -13.3333, 0, 13.3333, -6.6667, 0, 13.3333, -13.3333, 0, 20, -20, 0, 20, -13.3333, 0, 13.3333, -20, 0, 20, -20, 0, 13.3333, -13.3333, 0, 13.3333, 20, 0, 13.3333, 13.3333, 0, 13.3333, 20, 0, 6.6667, 13.3333, 0, 13.3333, 13.3333, 0, 6.6667, 20, 0, 6.6667, 13.3333, 0, 13.3333, 6.6667, 0, 13.3333, 13.3333, 0, 6.6667, 6.6667, 0, 13.3333, 6.6667, 0, 6.6667, 13.3333, 0, 6.6667, 6.6667, 0, 13.3333, 0, 0, 13.3333, 6.6667, 0, 6.6667, 0, 0, 13.3333, 0, 0, 6.6667, 6.6667, 0, 6.6667, 0, 0, 13.3333, -6.6667, 0, 13.3333, 0, 0, 6.6667, -6.6667, 0, 13.3333, -6.6667, 0, 6.6667, 0, 0, 6.6667, -6.6667, 0, 13.3333, -13.3333, 0, 13.3333, -6.6667, 0, 6.6667, -13.3333, 0, 13.3333, -13.3333, 0, 6.6667, -6.6667, 0, 6.6667, -13.3333, 0, 13.3333, -20, 0, 13.3333, -13.3333, 0, 6.6667, -20, 0, 13.3333, -20, 0, 6.6667, -13.3333, 0, 6.6667, 20, 0, 6.6667, 13.3333, 0, 6.6667, 20, 0, 0, 13.3333, 0, 6.6667, 13.3333, 0, 0, 20, 0, 0, 13.3333, 0, 6.6667, 6.6667, 0, 6.6667, 13.3333, 0, 0, 6.6667, 0, 6.6667, 6.6667, 0, 0, 13.3333, 0, 0, 6.6667, 0, 6.6667, 0, 0, 6.6667, 6.6667, 0, 0, 0, 0, 6.6667, 0, 0, 0, 6.6667, 0, 0, 0, 0, 6.6667, -6.6667, 0, 6.6667, 0, 0, 0, -6.6667, 0, 6.6667, -6.6667, 0, 0, 0, 0, 0, -6.6667, 0, 6.6667, -13.3333, 0, 6.6667, -6.6667, 0, 0, -13.3333, 0, 6.6667, -13.3333, 0, 0, -6.6667, 0, 0, -13.3333, 0, 6.6667, -20, 0, 6.6667, -13.3333, 0, 0, -20, 0, 6.6667, -20, 0, 0, -13.3333, 0, 0, 20, 0, 0, 13.3333, 0, 0, 20, 0, -6.6667, 13.3333, 0, 0, 13.3333, 0, -6.6667, 20, 0, -6.6667, 13.3333, 0, 0, 6.6667, 0, 0, 13.3333, 0, -6.6667, 6.6667, 0, 0, 6.6667, 0, -6.6667, 13.3333, 0, -6.6667, 6.6667, 0, 0, 0, 0, 0, 6.6667, 0, -6.6667, 0, 0, 0, 0, 0, -6.6667, 6.6667, 0, -6.6667, 0, 0, 0, -6.6667, 0, 0, 0, 0, -6.6667, -6.6667, 0, 0, -6.6667, 0, -6.6667, 0, 0, -6.6667, -6.6667, 0, 0, -13.3333, 0, 0, -6.6667, 0, -6.6667, -13.3333, 0, 0, -13.3333, 0, -6.6667, -6.6667, 0, -6.6667, -13.3333, 0, 0, -20, 0, 0, -13.3333, 0, -6.6667, -20, 0, 0, -20, 0, -6.6667, -13.3333, 0, -6.6667, 20, 0, -6.6667, 13.3333, 0, -6.6667, 20, 0, -13.3333, 13.3333, 0, -6.6667, 13.3333, 0, -13.3333, 20, 0, -13.3333, 13.3333, 0, -6.6667, 6.6667, 0, -6.6667, 13.3333, 0, -13.3333, 6.6667, 0, -6.6667, 6.6667, 0, -13.3333, 13.3333, 0, -13.3333, 6.6667, 0, -6.6667, 0, 0, -6.6667, 6.6667, 0, -13.3333, 0, 0, -6.6667, 0, 0, -13.3333, 6.6667, 0, -13.3333, 0, 0, -6.6667, -6.6667, 0, -6.6667, 0, 0, -13.3333, -6.6667, 0, -6.6667, -6.6667, 0, -13.3333, 0, 0, -13.3333, -6.6667, 0, -6.6667, -13.3333, 0, -6.6667, -6.6667, 0, -13.3333, -13.3333, 0, -6.6667, -13.3333, 0, -13.3333, -6.6667, 0, -13.3333, -13.3333, 0, -6.6667, -20, 0, -6.6667, -13.3333, 0, -13.3333, -20, 0, -6.6667, -20, 0, -13.3333, -13.3333, 0, -13.3333, 20, 0, -13.3333, 13.3333, 0, -13.3333, 20, 0, -20, 13.3333, 0, -13.3333, 13.3333, 0, -20, 20, 0, -20, 13.3333, 0, -13.3333, 6.6667, 0, -13.3333, 13.3333, 0, -20, 6.6667, 0, -13.3333, 6.6667, 0, -20, 13.3333, 0, -20, 6.6667, 0, -13.3333, 0, 0, -13.3333, 6.6667, 0, -20, 0, 0, -13.3333, 0, 0, -20, 6.6667, 0, -20, 0, 0, -13.3333, -6.6667, 0, -13.3333, 0, 0, -20, -6.6667, 0, -13.3333, -6.6667, 0, -20, 0, 0, -20, -6.6667, 0, -13.3333, -13.3333, 0, -13.3333, -6.6667, 0, -20, -13.3333, 0, -13.3333, -13.3333, 0, -20, -6.6667, 0, -20, -13.3333, 0, -13.3333, -20, 0, -13.3333, -13.3333, 0, -20, -20, 0, -13.3333, -20, 0, -20, -13.3333, 0, -20 )
[node name="steering_test" type="Spatial"]
script = ExtResource( 1 )
[node name="DirectionalLight" type="DirectionalLight" parent="."]
transform = Transform( 1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 20, 0 )
shadow_enabled = true
[node name="front" type="Spatial" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -5 )
[node name="right" type="Spatial" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 2.07902, 0, -0.0847001 )
[node name="left" type="Spatial" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -3.18049, 0, -0.0847001 )
[node name="target" type="Spatial" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -3.18049, 0, 3.45624 )
[node name="MeshInstance" type="MeshInstance" parent="target"]
mesh = SubResource( 3 )
material/0 = null
[node name="VehicleBody" type="VehicleBody" parent="."]
transform = Transform( -0.000366807, 0, -1, 0, 1, 0, 1, 0, -0.000366807, 0, 1.45468, 0 )
mass = 2000.0
[node name="MeshInstance" type="MeshInstance" parent="VehicleBody"]
mesh = SubResource( 1 )
skeleton = NodePath("../..")
material/0 = null
[node name="MeshInstance2" type="MeshInstance" parent="VehicleBody"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.2 )
mesh = SubResource( 2 )
skeleton = NodePath("../..")
material/0 = null
[node name="CollisionShape" type="CollisionShape" parent="VehicleBody"]
shape = SubResource( 4 )
[node name="VehicleWheel" type="VehicleWheel" parent="VehicleBody"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.7, -0.933, 1.321 )
use_as_steering = true
suspension_stiffness = 40.0
suspension_max_force = 12000.0
[node name="MeshInstance" type="MeshInstance" parent="VehicleBody/VehicleWheel"]
transform = Transform( 0.2, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 )
mesh = SubResource( 5 )
material/0 = null
[node name="VehicleWheel2" type="VehicleWheel" parent="VehicleBody"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.7, -0.933, 1.321 )
use_as_steering = true
suspension_stiffness = 40.0
suspension_max_force = 12000.0
[node name="MeshInstance" type="MeshInstance" parent="VehicleBody/VehicleWheel2"]
transform = Transform( 0.3, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 )
mesh = SubResource( 6 )
material/0 = null
[node name="VehicleWheel3" type="VehicleWheel" parent="VehicleBody"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.7, -0.933, -1.32477 )
use_as_traction = true
suspension_stiffness = 40.0
suspension_max_force = 12000.0
[node name="MeshInstance" type="MeshInstance" parent="VehicleBody/VehicleWheel3"]
transform = Transform( 0.2, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 )
mesh = SubResource( 5 )
material/0 = null
[node name="VehicleWheel4" type="VehicleWheel" parent="VehicleBody"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.7, -0.933, -1.32477 )
use_as_traction = true
suspension_stiffness = 40.0
suspension_max_force = 12000.0
[node name="MeshInstance" type="MeshInstance" parent="VehicleBody/VehicleWheel4"]
transform = Transform( 0.3, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 )
mesh = SubResource( 6 )
material/0 = null
[node name="Camera" type="Camera" parent="."]
transform = Transform( 0.0659952, 0.422312, -0.904045, 0, 0.90602, 0.423235, 0.99782, -0.0279315, 0.059793, -9.97146, 5.01123, -0.697941 )
environment = SubResource( 10 )
[node name="MeshInstance" type="MeshInstance" parent="."]
mesh = SubResource( 7 )
material/0 = null
[node name="StaticBody" type="StaticBody" parent="MeshInstance"]
[node name="CollisionShape" type="CollisionShape" parent="MeshInstance/StaticBody"]
shape = SubResource( 8 )