Răsfoiți Sursa

Merge pull request #385 from aaronfranke/truck-town

Update and improve Truck Town for Godot 3.1.2
Aaron Franke 5 ani în urmă
părinte
comite
a5b8cd11d9

Fișier diff suprimat deoarece este prea mare
+ 4 - 4
3d/truck_town/car_base.tscn


+ 14 - 12
3d/truck_town/car_select.gd

@@ -1,32 +1,34 @@
-
 extends Control
 
-# Member variables
 var town = null
 
-
-func _back():
-	town.queue_free()
-	show()
+func _process(_delta):
+	if Input.is_action_just_pressed("back"):
+		_on_Back_pressed()
 
 
 func _load_scene(car):
 	var tt = load(car).instance()
 	tt.set_name("car")
 	town = load("res://town_scene.tscn").instance()
-	town.get_node("instance_pos").add_child(tt)
-	town.get_node("back").connect("pressed", self, "_back")
+	town.get_node("InstancePos").add_child(tt)
+	town.get_node("Back").connect("pressed", self, "_on_Back_pressed")
 	get_parent().add_child(town)
 	hide()
 
 
-func _on_van_1_pressed():
+func _on_Back_pressed():
+	town.queue_free()
+	show()
+
+
+func _on_MiniVan_pressed():
 	_load_scene("res://car_base.tscn")
 
 
-func _on_van_2_pressed():
+func _on_TrailerTruck_pressed():
 	_load_scene("res://trailer_truck.tscn")
 
 
-func _on_van_3_pressed():
-	_load_scene("res://crane.tscn")
+func _on_TowTruck_pressed():
+	_load_scene("res://tow_truck.tscn")

+ 7 - 7
3d/truck_town/car_select.tscn

@@ -5,7 +5,7 @@
 [ext_resource path="res://Images/choose_trailer.png" type="Texture" id=3]
 [ext_resource path="res://Images/choose_tow.png" type="Texture" id=4]
 
-[node name="base" type="Control"]
+[node name="CarSelect" type="Control"]
 anchor_left = 0.5
 anchor_top = 0.5
 anchor_right = 0.5
@@ -22,7 +22,7 @@ __meta__ = {
 "_edit_use_anchors_": false
 }
 
-[node name="van 1" type="Button" parent="."]
+[node name="MiniVan" type="Button" parent="."]
 margin_left = 4.0
 margin_top = 160.0
 margin_right = 340.0
@@ -31,7 +31,7 @@ size_flags_horizontal = 2
 size_flags_vertical = 2
 icon = ExtResource( 2 )
 
-[node name="van 2" type="Button" parent="."]
+[node name="TrailerTruck" type="Button" parent="."]
 margin_left = 344.0
 margin_top = 160.0
 margin_right = 680.0
@@ -40,7 +40,7 @@ size_flags_horizontal = 2
 size_flags_vertical = 2
 icon = ExtResource( 3 )
 
-[node name="van 3" type="Button" parent="."]
+[node name="TowTruck" type="Button" parent="."]
 margin_left = 684.0
 margin_top = 160.0
 margin_right = 1020.0
@@ -48,6 +48,6 @@ margin_bottom = 400.0
 size_flags_horizontal = 2
 size_flags_vertical = 2
 icon = ExtResource( 4 )
-[connection signal="pressed" from="van 1" to="." method="_on_van_1_pressed"]
-[connection signal="pressed" from="van 2" to="." method="_on_van_2_pressed"]
-[connection signal="pressed" from="van 3" to="." method="_on_van_3_pressed"]
+[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"]

+ 30 - 37
3d/truck_town/follow_camera.gd

@@ -1,57 +1,50 @@
-
 extends Camera
 
-# Member variables
-var collision_exception = []
 export var min_distance = 0.5
 export var max_distance = 4.0
 export var angle_v_adjust = 0.0
-export var autoturn_ray_aperture = 25
-export var autoturn_speed = 50
+
+var collision_exception = []
 var max_height = 2.0
 var min_height = 0
 
+func _ready():
+	# Find collision exceptions for ray.
+	var node = self
+	while(node):
+		if (node is RigidBody):
+			collision_exception.append(node.get_rid())
+			break
+		else:
+			node = node.get_parent()
+	
+	# This detaches the camera transform from the parent spatial node.
+	set_as_toplevel(true)
+
 
-func _physics_process(dt):
+func _physics_process(_delta):
 	var target = get_parent().get_global_transform().origin
 	var pos = get_global_transform().origin
-	var up = Vector3(0, 1, 0)
-	
-	var delta = pos - target
 	
-	# Regular delta follow
+	var from_target = pos - target
 	
-	# Check ranges
-	if (delta.length() < min_distance):
-		delta = delta.normalized()*min_distance
-	elif (delta.length() > max_distance):
-		delta = delta.normalized()*max_distance
+	# Check ranges.
+	if from_target.length() < min_distance:
+		from_target = from_target.normalized() * min_distance
+	elif from_target.length() > max_distance:
+		from_target = from_target.normalized() * max_distance
 	
-	# Check upper and lower height
-	if ( delta.y > max_height):
-		delta.y = max_height
-	if ( delta.y < min_height):
-		delta.y = min_height
+	# 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
 	
-	pos = target + delta
+	pos = target + from_target
 	
-	look_at_from_position(pos, target, up)
+	look_at_from_position(pos, target, Vector3.UP)
 	
 	# Turn a little up or down
 	var t = get_transform()
-	t.basis = Basis(t.basis[0], deg2rad(angle_v_adjust))*t.basis
+	t.basis = Basis(t.basis[0], deg2rad(angle_v_adjust)) * t.basis
 	set_transform(t)
-
-
-func _ready():
-	# Find collision exceptions for ray
-	var node = self
-	while(node):
-		if (node is RigidBody):
-			collision_exception.append(node.get_rid())
-			break
-		else:
-			node = node.get_parent()
-	
-	# This detaches the camera transform from the parent spatial node
-	set_as_toplevel(true)

+ 37 - 0
3d/truck_town/project.godot

@@ -26,6 +26,43 @@ window/stretch/aspect="expand"
 window/height=720
 window/width=1280
 
+[input]
+
+accelerate={
+"deadzone": 0.5,
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"unicode":0,"echo":false,"script":null)
+, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"unicode":0,"echo":false,"script":null)
+, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":0,"pressure":0.0,"pressed":false,"script":null)
+ ]
+}
+reverse={
+"deadzone": 0.5,
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null)
+, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"unicode":0,"echo":false,"script":null)
+, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":1,"pressure":0.0,"pressed":false,"script":null)
+ ]
+}
+turn_left={
+"deadzone": 0.5,
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null)
+, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"unicode":0,"echo":false,"script":null)
+, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null)
+ ]
+}
+turn_right={
+"deadzone": 0.5,
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null)
+, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"unicode":0,"echo":false,"script":null)
+, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null)
+ ]
+}
+back={
+"deadzone": 0.5,
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777217,"unicode":0,"echo":false,"script":null)
+, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":11,"pressure":0.0,"pressed":false,"script":null)
+ ]
+}
+
 [rasterizer]
 
 shadow_filter=3

Fișier diff suprimat deoarece este prea mare
+ 2 - 5
3d/truck_town/tow_truck.tscn


Fișier diff suprimat deoarece este prea mare
+ 0 - 10
3d/truck_town/town_mesh.tscn


+ 6 - 51
3d/truck_town/town_scene.tscn

@@ -1,66 +1,21 @@
 [gd_scene load_steps=2 format=2]
 
-[ext_resource path="res://trucktown.tscn" type="PackedScene" id=1]
+[ext_resource path="res://town_mesh.tscn" type="PackedScene" id=1]
 
-[node name="town_scene" type="Spatial" index="0"]
+[node name="TownScene" type="Spatial"]
 
-[node name="Truck_Town" parent="." index="0" instance=ExtResource( 1 )]
-
-[node name="instance_pos" type="Position3D" parent="." index="1"]
+[node name="TownMesh" parent="." instance=ExtResource( 1 )]
 
+[node name="InstancePos" type="Position3D" parent="."]
 transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 13.2039, 6.67095, -37.6042 )
-_sections_unfolded = [ "Transform" ]
-
-[node name="back" type="Button" parent="." index="2"]
 
-anchor_left = 0.0
-anchor_top = 0.0
-anchor_right = 0.0
-anchor_bottom = 0.0
+[node name="Back" type="Button" parent="."]
 margin_left = 17.0
 margin_top = 9.0
 margin_right = 85.0
 margin_bottom = 41.0
-rect_pivot_offset = Vector2( 0, 0 )
-focus_mode = 2
-mouse_filter = 0
-mouse_default_cursor_shape = 0
-size_flags_horizontal = 1
-size_flags_vertical = 1
-toggle_mode = false
-enabled_focus_mode = 2
-shortcut = null
-group = null
 text = "<- Back!"
-flat = false
-align = 1
-
-[node name="DirectionalLight" type="DirectionalLight" parent="." index="3"]
 
+[node name="DirectionalLight" type="DirectionalLight" parent="."]
 transform = Transform( 1, 0, 0, 0, -0.629475, 0.777021, 0, -0.777021, -0.629475, 0, 24.4076, 0 )
-layers = 1
-light_color = Color( 1, 1, 1, 1 )
-light_energy = 1.0
-light_indirect_energy = 1.0
-light_negative = false
-light_specular = 0.5
-light_bake_mode = 1
-light_cull_mask = -1
 shadow_enabled = true
-shadow_color = Color( 0, 0, 0, 1 )
-shadow_bias = 0.1
-shadow_contact = 0.0
-shadow_reverse_cull_face = false
-editor_only = false
-directional_shadow_mode = 2
-directional_shadow_split_1 = 0.1
-directional_shadow_split_2 = 0.2
-directional_shadow_split_3 = 0.5
-directional_shadow_blend_splits = false
-directional_shadow_normal_bias = 0.8
-directional_shadow_bias_split_scale = 0.25
-directional_shadow_depth_range = 0
-directional_shadow_max_distance = 200.0
-_sections_unfolded = [ "Shadow" ]
-
-

Fișier diff suprimat deoarece este prea mare
+ 1 - 4
3d/truck_town/trailer_truck.tscn


+ 4 - 9
3d/truck_town/vehicle.gd

@@ -1,6 +1,5 @@
 extends VehicleBody
 
-# Member variables
 const STEER_SPEED = 1
 const STEER_LIMIT = 0.4
 
@@ -12,19 +11,15 @@ export var engine_force_value = 40
 func _physics_process(delta):
 	var fwd_mps = transform.basis.xform_inv(linear_velocity).x
 	
-	if Input.is_action_pressed("ui_left"):
-		steer_target = STEER_LIMIT
-	elif Input.is_action_pressed("ui_right"):
-		steer_target = -STEER_LIMIT
-	else:
-		steer_target = 0
+	steer_target = Input.get_action_strength("turn_left") - Input.get_action_strength("turn_right")
+	steer_target *= STEER_LIMIT
 	
-	if Input.is_action_pressed("ui_up"):
+	if Input.is_action_pressed("accelerate"):
 		engine_force = engine_force_value
 	else:
 		engine_force = 0
 	
-	if Input.is_action_pressed("ui_down"):
+	if Input.is_action_pressed("reverse"):
 		if (fwd_mps >= -1):
 			engine_force = -engine_force_value
 		else:

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff