Start work on obstacles

This commit is contained in:
Matthew Welch 2024-10-04 18:25:33 -07:00
parent d6da1268d8
commit 932dfd8177
6 changed files with 47 additions and 12 deletions

View File

@ -31,16 +31,6 @@ func turn(direction):
paths[path_index+1] = get_path_by_direction(current_direction) paths[path_index+1] = get_path_by_direction(current_direction)
#func has_next_path() -> bool:
#return on_main_path
#func get_next_path() -> Path3D:
#if not on_main_path:
#return get_path_by_direction(current_direction)
#return null
func get_path_by_direction(direction) -> Path3D: func get_path_by_direction(direction) -> Path3D:
if direction == "forward" and path_forward != null: if direction == "forward" and path_forward != null:
return path_forward return path_forward

View File

@ -1,6 +1,7 @@
[gd_scene load_steps=10 format=3 uid="uid://b88nuwe42bhc1"] [gd_scene load_steps=11 format=3 uid="uid://b88nuwe42bhc1"]
[ext_resource type="Script" path="res://Tiles/TileTurn.gd" id="1_wj6en"] [ext_resource type="Script" path="res://Tiles/TileTurn.gd" id="1_wj6en"]
[ext_resource type="PackedScene" uid="uid://dkcjoccsgbggg" path="res://obstacles/obstacle.tscn" id="2_tnkvo"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_cwetn"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_cwetn"]
cull_mode = 2 cull_mode = 2
@ -22,7 +23,7 @@ point_count = 2
[sub_resource type="Curve3D" id="Curve3D_5ouye"] [sub_resource type="Curve3D" id="Curve3D_5ouye"]
_data = { _data = {
"points": PackedVector3Array(0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, -5), "points": PackedVector3Array(0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, -6),
"tilts": PackedFloat32Array(0, 0) "tilts": PackedFloat32Array(0, 0)
} }
point_count = 2 point_count = 2
@ -104,3 +105,6 @@ tilt_enabled = false
[node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D"] [node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0194125, 2.2431, 4.34685) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0194125, 2.2431, 4.34685)
shape = SubResource("BoxShape3D_uvh3q") shape = SubResource("BoxShape3D_uvh3q")
[node name="Obstacle" parent="." instance=ExtResource("2_tnkvo")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, -5.14771)

View File

@ -31,3 +31,14 @@ func _process(delta: float):
var travel: float = speed * delta var travel: float = speed * delta
tile.follow.progress += travel tile.follow.progress += travel
total_distance += travel total_distance += travel
func _on_area_entered(area):
if area is Obstacle:
handle_obstacle(area)
func handle_obstacle(obstacle: Obstacle):
if obstacle.effect == Obstacle.ObstacleEffect.Kill:
print("kill")
speed = 0

View File

@ -20,3 +20,5 @@ skeleton = NodePath("")
[node name="Camera3D" type="Camera3D" parent="."] [node name="Camera3D" type="Camera3D" parent="."]
transform = Transform3D(1, -4.52535e-08, 1.68888e-07, -1.77636e-15, 0.965926, 0.258819, -1.74846e-07, -0.258819, 0.965926, 0, 2, 2.558) transform = Transform3D(1, -4.52535e-08, 1.68888e-07, -1.77636e-15, 0.965926, 0.258819, -1.74846e-07, -0.258819, 0.965926, 0, 2, 2.558)
[connection signal="area_entered" from="." to="." method="_on_area_entered"]

16
obstacles/obstacle.gd Normal file
View File

@ -0,0 +1,16 @@
extends Area3D
class_name Obstacle
@export var effect: ObstacleEffect
enum ObstacleEffect {
Kill,
Trip,
}
func _ready():
pass
func _process(delta):
pass

12
obstacles/obstacle.tscn Normal file
View File

@ -0,0 +1,12 @@
[gd_scene load_steps=3 format=3 uid="uid://dkcjoccsgbggg"]
[ext_resource type="Script" path="res://obstacles/obstacle.gd" id="1_ab8so"]
[sub_resource type="BoxShape3D" id="BoxShape3D_c6wik"]
size = Vector3(10, 2, 0.5)
[node name="Obstacle" type="Area3D"]
script = ExtResource("1_ab8so")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
shape = SubResource("BoxShape3D_c6wik")