Skip to content

Commit d90e401

Browse files
committed
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).
1 parent 99ad90b commit d90e401

File tree

8 files changed

+24
-13
lines changed

8 files changed

+24
-13
lines changed

3d/truck_town/car_base.tscn

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ current = true
207207
fov = 74.0
208208
near = 0.1
209209
script = ExtResource( 5 )
210-
max_distance = 7.0
210+
min_distance = 3.0
211+
max_distance = 4.0
212+
height = 1.25
211213

212214
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
213215
_import_path = NodePath("AnimationPlayer")

3d/truck_town/car_select.gd

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@ func _load_scene(car):
1818

1919

2020
func _on_Back_pressed():
21-
town.queue_free()
22-
show()
21+
if is_instance_valid(town):
22+
# Currently in the town, go back to main menu.
23+
town.queue_free()
24+
show()
25+
else:
26+
# In main menu, exit the game.
27+
get_tree().quit()
2328

2429

2530
func _on_MiniVan_pressed():

3d/truck_town/car_select.tscn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ margin_bottom = 400.0
4848
size_flags_horizontal = 2
4949
size_flags_vertical = 2
5050
icon = ExtResource( 4 )
51+
5152
[connection signal="pressed" from="MiniVan" to="." method="_on_MiniVan_pressed"]
5253
[connection signal="pressed" from="TrailerTruck" to="." method="_on_TrailerTruck_pressed"]
5354
[connection signal="pressed" from="TowTruck" to="." method="_on_TowTruck_pressed"]

3d/truck_town/follow_camera.gd

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
extends Camera
22

3-
export var min_distance = 0.5
3+
export var min_distance = 2.0
44
export var max_distance = 4.0
55
export var angle_v_adjust = 0.0
66

77
var collision_exception = []
8-
var max_height = 2.0
9-
var min_height = 0
8+
export var height = 1.5
109

1110
func _ready():
1211
# Find collision exceptions for ray.
@@ -34,11 +33,7 @@ func _physics_process(_delta):
3433
elif from_target.length() > max_distance:
3534
from_target = from_target.normalized() * max_distance
3635

37-
# Check upper and lower height.
38-
if from_target.y > max_height:
39-
from_target.y = max_height
40-
if from_target.y < min_height:
41-
from_target.y = min_height
36+
from_target.y = height
4237

4338
pos = target + from_target
4439

3d/truck_town/project.godot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ back={
7070
]
7171
}
7272

73+
[physics]
74+
75+
3d/default_gravity=11.0
76+
7377
[rasterizer]
7478

7579
shadow_filter=3

3d/truck_town/tow_truck.tscn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,9 @@ current = true
337337
fov = 74.0
338338
near = 0.1
339339
script = ExtResource( 5 )
340+
min_distance = 5.0
340341
max_distance = 7.0
342+
height = 1.75
341343

342344
[node name="CollisionShape" type="CollisionShape" parent="Body"]
343345
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.391365, 0.158069 )

3d/truck_town/trailer_truck.tscn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,9 @@ current = true
385385
fov = 74.0
386386
near = 0.1
387387
script = ExtResource( 5 )
388+
min_distance = 5.0
388389
max_distance = 7.0
390+
height = 2.5
389391

390392
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
391393
_import_path = NodePath("AnimationPlayer")

3d/truck_town/vehicle.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
extends VehicleBody
22

3-
const STEER_SPEED = 1
3+
const STEER_SPEED = 1.5
44
const STEER_LIMIT = 0.4
55

66
var steer_target = 0
77

8-
export var engine_force_value = 40
8+
export var engine_force_value = 85
99

1010
func _physics_process(delta):
1111
var fwd_mps = transform.basis.xform_inv(linear_velocity).x

0 commit comments

Comments
 (0)