Skip to content

Commit

Permalink
Merge pull request #998 from Calinou/truck-town-mobile
Browse files Browse the repository at this point in the history
Add mobile controls and optimized settings to Truck Town
  • Loading branch information
akien-mga authored Jan 19, 2024
2 parents 81ea8ed + cdbdbac commit b36d6f0
Show file tree
Hide file tree
Showing 23 changed files with 278 additions and 80 deletions.
12 changes: 8 additions & 4 deletions 3d/truck_town/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ varying complexity using vehicle physics.
Controls:

- <kbd>Up Arrow</kbd>, <kbd>W</kbd>, <kbd>Gamepad Right Trigger</kbd>, <kbd>Gamepad A/Cross</kbd>: Accelerate
- <kbd>Down Arrow</kbd>, <kbd>S</kbd>, <kbd>Gamepad Left Trigger</kbd>, <kbd>Gamepad B/Circle</kbd> : Brake
- <kbd>Left Arrow</kbd>, <kbd>Gamepad Left Stick</kbd>: Steer left
- <kbd>Right Arrow</kbd>, <kbd>Gamepad Left Stick</kbd>: Steer right
- <kbd>Down Arrow</kbd>, <kbd>S</kbd>, <kbd>Gamepad Left Trigger</kbd>, <kbd>Gamepad B/Circle</kbd>, <kbd>Gamepad X/Square</kbd>: Brake/reverse
- <kbd>Left Arrow</kbd>, <kbd>Gamepad Left Stick</kbd>, <kbd>Gamepad D-Pad Left</kbd>: Steer left
- <kbd>Right Arrow</kbd>, <kbd>Gamepad Left Stick</kbd>, <kbd>Gamepad D-Pad Right</kbd>: Steer right
- <kbd>U</kbd>, <kbd>Gamepad Select</kbd>, left-click speedometer: Change speedometer unit (m/s, km/h, mph)
- <kbd>C</kbd>, <kbd>Gamepad Y/Triangle</kbd>: Change camera (exterior, interior, top-down)
- <kbd>Escape</kbd>, <kbd>Gamepad D-Pad Up</kbd>: Go back to menu (press again to exit)

On mobile platforms, the vehicle automatically accelerates. Touch the left and
right edges of the screen to steer. Touch the middle of the screen to
brake/reverse (this also temporarily stops acceleration).

Language: GDScript

Renderer: Forward Plus
Renderer: Forward+ on desktop, Mobile on mobile

Check out this demo on the asset library: https://godotengine.org/asset-library/asset/524

Expand Down
11 changes: 9 additions & 2 deletions 3d/truck_town/car_select/car_select.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ size_flags_vertical = 2
script = ExtResource("1")

[node name="HBoxContainer" type="HBoxContainer" parent="."]
anchors_preset = 14
layout_mode = 0
anchor_top = 0.5
anchor_right = 1.0
anchor_bottom = 0.5
Expand All @@ -38,22 +38,25 @@ grow_vertical = 2
alignment = 1

[node name="MiniVan" type="Button" parent="HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 6
size_flags_vertical = 4
icon = ExtResource("2")

[node name="TrailerTruck" type="Button" parent="HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 6
size_flags_vertical = 4
icon = ExtResource("3")

[node name="TowTruck" type="Button" parent="HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 6
size_flags_vertical = 4
icon = ExtResource("4")

[node name="Label" type="Label" parent="."]
anchors_preset = 5
layout_mode = 0
anchor_left = 0.5
anchor_right = 0.5
offset_left = -180.0
Expand All @@ -62,8 +65,12 @@ offset_right = 180.0
offset_bottom = 123.0
grow_horizontal = 2
theme_override_colors/font_color = Color(0.494118, 0.858824, 0.960784, 1)
theme_override_colors/font_shadow_color = Color(0, 0.25098, 1, 0.12549)
theme_override_colors/font_outline_color = Color(0.105882, 0.278431, 0.47451, 1)
theme_override_constants/shadow_offset_x = 6
theme_override_constants/shadow_offset_y = 6
theme_override_constants/outline_size = 38
theme_override_constants/shadow_outline_size = 38
theme_override_fonts/font = SubResource("FontVariation_hqcvw")
theme_override_font_sizes/font_size = 64
text = "Truck Town"
Expand Down
2 changes: 1 addition & 1 deletion 3d/truck_town/car_select/choose_tow.png.import
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ dest_files=["res://.godot/imported/choose_tow.png-e1d5f4ba7eb707eed82d65f6944c64
[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/bptc_ldr=0
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
Expand Down
2 changes: 1 addition & 1 deletion 3d/truck_town/car_select/choose_trailer.png.import
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ dest_files=["res://.godot/imported/choose_trailer.png-42b178b0fc9d742f9f23bb1d9f
[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/bptc_ldr=0
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
Expand Down
2 changes: 1 addition & 1 deletion 3d/truck_town/car_select/choose_van.png.import
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ dest_files=["res://.godot/imported/choose_van.png-a2669a1a5e1faa5c8245c7e87ce8c4
[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/bptc_ldr=0
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
Expand Down
59 changes: 33 additions & 26 deletions 3d/truck_town/project.godot

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion 3d/truck_town/town/materials/cement.webp.import
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ dest_files=["res://.godot/imported/cement.webp-a59028ca151ccfb7e6020be6c141b163.
[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/bptc_ldr=0
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
Expand Down
2 changes: 1 addition & 1 deletion 3d/truck_town/town/materials/grass.webp.import
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ dest_files=["res://.godot/imported/grass.webp-0ccf2a619a3f121234da585c8abbfdba.c
[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/bptc_ldr=0
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
Expand Down
81 changes: 78 additions & 3 deletions 3d/truck_town/town/town_scene.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=32 format=3 uid="uid://d0ygmqpylq0wy"]
[gd_scene load_steps=36 format=3 uid="uid://d0ygmqpylq0wy"]

[ext_resource type="PackedScene" uid="uid://dfdgytsvtqxwv" path="res://town/truck_town.glb" id="1_x0dmm"]
[ext_resource type="Script" path="res://spedometer.gd" id="2"]
Expand All @@ -12,6 +12,24 @@ action = &"cycle_speedometer_unit"
[sub_resource type="Shortcut" id="Shortcut_msvqx"]
events = [SubResource("InputEventAction_a4722")]

[sub_resource type="Gradient" id="Gradient_jks6h"]
offsets = PackedFloat32Array(0)
colors = PackedColorArray(1, 1, 1, 0.25098)

[sub_resource type="GradientTexture2D" id="GradientTexture2D_m8ylb"]
gradient = SubResource("Gradient_jks6h")
width = 128
height = 128

[sub_resource type="Gradient" id="Gradient_1rnu2"]
offsets = PackedFloat32Array(0.00645161)
colors = PackedColorArray(1, 0, 0, 0.25098)

[sub_resource type="GradientTexture2D" id="GradientTexture2D_xu6xc"]
gradient = SubResource("Gradient_1rnu2")
width = 128
height = 128

[sub_resource type="BoxMesh" id="BoxMesh_x3c0g"]
size = Vector3(4096, 1, 4096)

Expand Down Expand Up @@ -102,7 +120,7 @@ data = PackedVector3Array(-2, 1, 2, 2, -1, 2, -2, -1, 2, -2, 1, -2, -2, -1, -2,
[node name="TruckTown" parent="." instance=ExtResource("1_x0dmm")]

[node name="InstancePos" type="Marker3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 14, 6, -40)
transform = Transform3D(1.31134e-07, 0, -1, 0, 1, 0, 1, 0, 1.31134e-07, 8, 3.36405, -16)

[node name="Spedometer" type="Button" parent="."]
custom_minimum_size = Vector2(140, 40)
Expand All @@ -118,10 +136,10 @@ offset_bottom = -24.0
grow_horizontal = 0
grow_vertical = 0
focus_mode = 0
shortcut_in_tooltip = false
action_mode = 0
shortcut = SubResource("Shortcut_msvqx")
shortcut_feedback = false
shortcut_in_tooltip = false
text = "Speed: ???"
script = ExtResource("2")

Expand All @@ -132,6 +150,63 @@ offset_right = 92.0
offset_bottom = 56.0
text = "« Back"

[node name="TouchTurnLeft" type="Control" parent="."]
layout_mode = 3
anchors_preset = 4
anchor_top = 0.5
anchor_bottom = 0.5
grow_vertical = 2

[node name="TurnLeft" type="TouchScreenButton" parent="TouchTurnLeft"]
modulate = Color(1, 1, 1, 0)
position = Vector2(0, -256)
scale = Vector2(2.5, 4)
texture_normal = SubResource("GradientTexture2D_m8ylb")
texture_pressed = SubResource("GradientTexture2D_xu6xc")
passby_press = true
action = "turn_left"
visibility_mode = 1

[node name="TouchReverse" type="Control" parent="."]
layout_mode = 3
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
grow_horizontal = 2
grow_vertical = 2

[node name="Reverse" type="TouchScreenButton" parent="TouchReverse"]
modulate = Color(1, 1, 1, 0)
position = Vector2(-256, -256)
scale = Vector2(4, 4)
texture_normal = SubResource("GradientTexture2D_m8ylb")
texture_pressed = SubResource("GradientTexture2D_xu6xc")
passby_press = true
action = "reverse"
visibility_mode = 1

[node name="TouchTurnRight" type="Control" parent="."]
layout_mode = 3
anchors_preset = 6
anchor_left = 1.0
anchor_top = 0.5
anchor_right = 1.0
anchor_bottom = 0.5
grow_horizontal = 0
grow_vertical = 2

[node name="TurnRight" type="TouchScreenButton" parent="TouchTurnRight"]
modulate = Color(1, 1, 1, 0)
position = Vector2(-320, -256)
scale = Vector2(2.5, 4)
texture_normal = SubResource("GradientTexture2D_m8ylb")
texture_pressed = SubResource("GradientTexture2D_xu6xc")
passby_press = true
action = "turn_right"
visibility_mode = 1

[node name="Environment" type="WorldEnvironment" parent="."]
environment = ExtResource("3_t0mbp")

Expand Down
2 changes: 2 additions & 0 deletions 3d/truck_town/town/truck_town.glb.import
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ skins/use_named_skins=false
animation/import=false
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
import_script/path=""
_subresources={
"materials": {
Expand Down Expand Up @@ -91,3 +92,4 @@ _subresources={
}
}
}
gltf/embedded_image_handling=1
2 changes: 1 addition & 1 deletion 3d/truck_town/vehicles/blob_shadow.png.import
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ dest_files=["res://.godot/imported/blob_shadow.png-543236f87c8fdb7d06671b1460d39
[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/bptc_ldr=0
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
Expand Down
17 changes: 12 additions & 5 deletions 3d/truck_town/vehicles/car_base.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=18 format=3 uid="uid://c1uai3rvx8hul"]
[gd_scene load_steps=19 format=3 uid="uid://c1uai3rvx8hul"]

[ext_resource type="Script" path="res://vehicles/vehicle.gd" id="1_r806m"]
[ext_resource type="Texture2D" uid="uid://d4ostmqwgytk" path="res://vehicles/particle_smoke.png" id="2_1gkvk"]
Expand Down Expand Up @@ -34,9 +34,11 @@ stream_3/weight = 1.0
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_fuuj3"]
transparency = 1
shading_mode = 0
vertex_color_use_as_albedo = true
albedo_color = Color(0.462745, 0.462745, 0.462745, 0.501961)
albedo_texture = ExtResource("2_1gkvk")
billboard_mode = 3
billboard_keep_scale = true
particles_anim_h_frames = 1
particles_anim_v_frames = 1
particles_anim_loop = false
Expand All @@ -47,9 +49,12 @@ proximity_fade_distance = 0.5
material = SubResource("StandardMaterial3D_fuuj3")

[sub_resource type="Curve" id="Curve_4j5vd"]
_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0]
_data = [Vector2(0, 0), 0.0, 0.0, 0, 0, Vector2(1, 1), 0.0, 0.0, 0, 0]
point_count = 2

[sub_resource type="Gradient" id="Gradient_p5xtl"]
colors = PackedColorArray(1, 1, 1, 1, 1, 1, 1, 0)

[node name="CarBase" type="Node3D"]

[node name="Body" type="VehicleBody3D" parent="."]
Expand Down Expand Up @@ -133,7 +138,7 @@ shape = SubResource("BoxShape3D_x74tc")
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.97449, 0)

[node name="Camera3D" type="Camera3D" parent="Body/CameraBase"]
transform = Transform3D(-0.709652, -0.170177, 0.683691, -2.11161e-08, 0.970391, 0.241539, -0.704552, 0.171409, -0.68864, 3.44908, 2.03236, -4.39379)
transform = Transform3D(-1, 2.11495e-08, -8.48259e-08, 0, 0.970296, 0.241922, 8.74228e-08, 0.241922, -0.970296, 0, 2.032, -4.394)
fov = 74.0
near = 0.1
script = ExtResource("4_6igu8")
Expand All @@ -155,7 +160,8 @@ attenuation_filter_cutoff_hz = 20500.0

[node name="CPUParticles3D" type="CPUParticles3D" parent="Body"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.201696, -0.022867, -1.10448)
amount = 100
amount = 125
lifetime = 1.25
mesh = SubResource("QuadMesh_30wks")
direction = Vector3(0, 1, -0.5)
gravity = Vector3(0, 0, 0)
Expand All @@ -165,10 +171,11 @@ damping_min = 0.05
damping_max = 0.05
angle_max = 360.0
scale_amount_curve = SubResource("Curve_4j5vd")
color_ramp = SubResource("Gradient_p5xtl")

[node name="BlobShadow" type="Decal" parent="Body"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.05)
extents = Vector3(0.8, 2, 1.5)
size = Vector3(1.6, 4, 3)
texture_albedo = ExtResource("11_3ryw5")
upper_fade = 2.0
lower_fade = 1.0
Expand Down
2 changes: 2 additions & 0 deletions 3d/truck_town/vehicles/meshes/meshes.glb.import
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
import_script/path=""
_subresources={
"materials": {
Expand Down Expand Up @@ -99,3 +100,4 @@ _subresources={
}
}
}
gltf/embedded_image_handling=1
Binary file modified 3d/truck_town/vehicles/meshes/minivan.res
Binary file not shown.
Binary file modified 3d/truck_town/vehicles/meshes/tow_truck.res
Binary file not shown.
Binary file modified 3d/truck_town/vehicles/meshes/truck_cab.res
Binary file not shown.
Binary file modified 3d/truck_town/vehicles/meshes/truck_trailer.res
Binary file not shown.
Binary file modified 3d/truck_town/vehicles/meshes/wheel.res
Binary file not shown.
2 changes: 1 addition & 1 deletion 3d/truck_town/vehicles/particle_smoke.png.import
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ dest_files=["res://.godot/imported/particle_smoke.png-740721ed7d039c3c932866a66d
[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/bptc_ldr=0
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
Expand Down
Loading

0 comments on commit b36d6f0

Please sign in to comment.