Improve controls and camera handling in the Truck Town demo

- Increase movement and steering speed significantly.
- Increase gravity slightly for a less floaty feeling.
- Simplify camera code (height is now constant).
- Tweaked camera distance and height to fit each vehicle.
- Fix script error when pressing Escape in the main menu
  (the demo will now quit).
This commit is contained in:
Hugo Locurcio 2021-02-21 19:58:36 +01:00
parent 99ad90bd0d
commit d90e401d2a
No known key found for this signature in database
GPG Key ID: 39E8F8BE30B0A49C
8 changed files with 24 additions and 13 deletions

View File

@ -207,7 +207,9 @@ current = true
fov = 74.0
near = 0.1
script = ExtResource( 5 )
max_distance = 7.0
min_distance = 3.0
max_distance = 4.0
height = 1.25
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
_import_path = NodePath("AnimationPlayer")

View File

@ -18,8 +18,13 @@ func _load_scene(car):
func _on_Back_pressed():
town.queue_free()
show()
if is_instance_valid(town):
# Currently in the town, go back to main menu.
town.queue_free()
show()
else:
# In main menu, exit the game.
get_tree().quit()
func _on_MiniVan_pressed():

View File

@ -48,6 +48,7 @@ margin_bottom = 400.0
size_flags_horizontal = 2
size_flags_vertical = 2
icon = ExtResource( 4 )
[connection signal="pressed" from="MiniVan" to="." method="_on_MiniVan_pressed"]
[connection signal="pressed" from="TrailerTruck" to="." method="_on_TrailerTruck_pressed"]
[connection signal="pressed" from="TowTruck" to="." method="_on_TowTruck_pressed"]

View File

@ -1,12 +1,11 @@
extends Camera
export var min_distance = 0.5
export var min_distance = 2.0
export var max_distance = 4.0
export var angle_v_adjust = 0.0
var collision_exception = []
var max_height = 2.0
var min_height = 0
export var height = 1.5
func _ready():
# Find collision exceptions for ray.
@ -34,11 +33,7 @@ func _physics_process(_delta):
elif from_target.length() > max_distance:
from_target = from_target.normalized() * max_distance
# Check upper and lower height.
if from_target.y > max_height:
from_target.y = max_height
if from_target.y < min_height:
from_target.y = min_height
from_target.y = height
pos = target + from_target

View File

@ -70,6 +70,10 @@ back={
]
}
[physics]
3d/default_gravity=11.0
[rasterizer]
shadow_filter=3

View File

@ -337,7 +337,9 @@ current = true
fov = 74.0
near = 0.1
script = ExtResource( 5 )
min_distance = 5.0
max_distance = 7.0
height = 1.75
[node name="CollisionShape" type="CollisionShape" parent="Body"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.391365, 0.158069 )

View File

@ -385,7 +385,9 @@ current = true
fov = 74.0
near = 0.1
script = ExtResource( 5 )
min_distance = 5.0
max_distance = 7.0
height = 2.5
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
_import_path = NodePath("AnimationPlayer")

View File

@ -1,11 +1,11 @@
extends VehicleBody
const STEER_SPEED = 1
const STEER_SPEED = 1.5
const STEER_LIMIT = 0.4
var steer_target = 0
export var engine_force_value = 40
export var engine_force_value = 85
func _physics_process(delta):
var fwd_mps = transform.basis.xform_inv(linear_velocity).x