mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-06 07:50:22 +01:00
Allow using WASD and controllers in Truck Town
This commit is contained in:
@@ -2,21 +2,26 @@ extends Control
|
||||
|
||||
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_Back_pressed():
|
||||
town.queue_free()
|
||||
show()
|
||||
|
||||
|
||||
func _on_MiniVan_pressed():
|
||||
_load_scene("res://car_base.tscn")
|
||||
|
||||
|
||||
@@ -1,12 +1,27 @@
|
||||
extends Camera
|
||||
|
||||
var collision_exception = []
|
||||
export var min_distance = 0.5
|
||||
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
|
||||
|
||||
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(_delta):
|
||||
var target = get_parent().get_global_transform().origin
|
||||
var pos = get_global_transform().origin
|
||||
@@ -33,17 +48,3 @@ func _physics_process(_delta):
|
||||
var t = get_transform()
|
||||
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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
|
||||
[node name="TownMesh" parent="." instance=ExtResource( 1 )]
|
||||
|
||||
[node name="instance_pos" type="Position3D" parent="."]
|
||||
[node name="InstancePos" type="Position3D" parent="."]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 13.2039, 6.67095, -37.6042 )
|
||||
|
||||
[node name="back" type="Button" parent="."]
|
||||
[node name="Back" type="Button" parent="."]
|
||||
margin_left = 17.0
|
||||
margin_top = 9.0
|
||||
margin_right = 85.0
|
||||
|
||||
@@ -11,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:
|
||||
|
||||
Reference in New Issue
Block a user