Start change to talk directly to a Tile instead of a Path3D

This commit is contained in:
Matthew Welch 2024-10-01 19:45:11 -07:00
parent 05d285a750
commit 9343dcd520
8 changed files with 154 additions and 14 deletions

View File

@ -4,10 +4,10 @@ class_name Tile
@onready var path = $MainPath as Path3D
@onready var follow = $MainPath/Follow as PathFollow3D
@onready var spawn_point = $SpawnPoint as Marker3D
var length: float:
get:
return path.curve.get_baked_length() as float
get = get_length
func _ready():
pass # Replace with function body.
@ -15,3 +15,15 @@ func _ready():
func _process(delta):
pass
func get_length():
return path.curve.get_baked_length()
func has_next_path() -> bool:
return false
func get_next_path():
return null

View File

@ -34,6 +34,9 @@ mesh = SubResource("PlaneMesh_rsriu")
transform = Transform3D(-4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0, 0, 1, 5, 1, 0)
mesh = SubResource("PlaneMesh_rsriu")
[node name="SpawnPoint" type="Marker3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -5)
[node name="MainPath" type="Path3D" parent="."]
curve = SubResource("Curve3D_q1k88")

View File

@ -35,6 +35,9 @@ mesh = SubResource("PlaneMesh_rsriu")
transform = Transform3D(-4.37114e-08, 1, 0, -0.866025, -3.78552e-08, -0.5, -0.5, -2.18557e-08, 0.866025, 5, 0.955342, 0.166667)
mesh = SubResource("PlaneMesh_rsriu")
[node name="SpawnPoint" type="Marker3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.56806, -4.67077)
[node name="MainPath" type="Path3D" parent="."]
curve = SubResource("Curve3D_q1k88")

61
Tiles/TileTurn.gd Normal file
View File

@ -0,0 +1,61 @@
extends Tile
class_name TileTurn
@onready var area_3d = $Area3D as Area3D
@onready var main_path = $MainPath as Path3D
@onready var main_follow = $MainPath/Follow as PathFollow3D
@onready var path_forward = $PathForward as Path3D
@onready var path_right = $PathRight as Path3D
@onready var path_left = $PathLeft as Path3D
var connected = false
var current_direction = "forward"
var on_main_path = true
func _ready():
pass
func _process(delta):
for area in area_3d.get_overlapping_areas():
if area is Character and not connected:
var character = area as Character
character.turn.connect(turn)
connected = true
if main_follow.progress_ratio >= 1 and on_main_path:
on_main_path = false
var marker = Utils.find_first_node_of_type(main_follow, Marker3D)
if current_direction == "forward" and path_forward != null:
marker.reparent($PathForward/Follow)
elif current_direction == "right" and path_right != null:
marker.reparent($PathRight/Follow)
elif current_direction == "left" and path_left != null:
marker.reparent($PathLeft/Follow)
func turn(direction):
current_direction = direction
func get_length():
return main_path.curve.get_baked_length() + path_forward.curve.get_baked_length()
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:
if direction == "forward" and path_forward != null:
return path_forward
elif direction == "right" and path_right != null:
return path_right
elif direction == "left" and path_left != null:
return path_left
return null

View File

@ -1,6 +1,6 @@
[gd_scene load_steps=6 format=3 uid="uid://b88nuwe42bhc1"]
[gd_scene load_steps=10 format=3 uid="uid://b88nuwe42bhc1"]
[ext_resource type="Script" path="res://Tiles/Tile.gd" id="1_6m2c8"]
[ext_resource type="Script" path="res://Tiles/TileTurn.gd" id="1_wj6en"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_cwetn"]
cull_mode = 2
@ -15,13 +15,37 @@ size = Vector2(2, 10)
[sub_resource type="Curve3D" id="Curve3D_q1k88"]
_data = {
"points": PackedVector3Array(0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0),
"tilts": PackedFloat32Array(0, 0, 0)
"points": PackedVector3Array(0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0),
"tilts": PackedFloat32Array(0, 0)
}
point_count = 3
point_count = 2
[sub_resource type="Curve3D" id="Curve3D_5ouye"]
_data = {
"points": PackedVector3Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -5),
"tilts": PackedFloat32Array(0, 0)
}
point_count = 2
[sub_resource type="Curve3D" id="Curve3D_dgywf"]
_data = {
"points": PackedVector3Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0),
"tilts": PackedFloat32Array(0, 0)
}
point_count = 2
[sub_resource type="Curve3D" id="Curve3D_25twk"]
_data = {
"points": PackedVector3Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -5, 0, 0),
"tilts": PackedFloat32Array(0, 0)
}
point_count = 2
[sub_resource type="BoxShape3D" id="BoxShape3D_uvh3q"]
size = Vector3(9.80943, 5.486, 17.6183)
[node name="Tile1" type="Node3D"]
script = ExtResource("1_6m2c8")
script = ExtResource("1_wj6en")
[node name="Floor" type="MeshInstance3D" parent="."]
mesh = SubResource("PlaneMesh_jju0s")
@ -34,6 +58,9 @@ mesh = SubResource("PlaneMesh_rsriu")
transform = Transform3D(1.91069e-15, -4.37114e-08, 1, -1, -4.37114e-08, 0, 4.37114e-08, -1, -4.37114e-08, 0, 1, -5)
mesh = SubResource("PlaneMesh_rsriu")
[node name="SpawnPoint" type="Marker3D" parent="."]
transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 5, 0, 0)
[node name="MainPath" type="Path3D" parent="."]
curve = SubResource("Curve3D_q1k88")
@ -42,3 +69,35 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 5)
rotation_mode = 1
loop = false
tilt_enabled = false
[node name="PathForward" type="Path3D" parent="."]
curve = SubResource("Curve3D_5ouye")
[node name="Follow" type="PathFollow3D" parent="PathForward"]
rotation_mode = 1
loop = false
tilt_enabled = false
[node name="PathRight" type="Path3D" parent="."]
curve = SubResource("Curve3D_dgywf")
[node name="Follow" type="PathFollow3D" parent="PathRight"]
transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0, 0, 0)
rotation_mode = 1
loop = false
tilt_enabled = false
[node name="PathLeft" type="Path3D" parent="."]
curve = SubResource("Curve3D_25twk")
[node name="Follow" type="PathFollow3D" parent="PathLeft"]
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0, 0, 0)
rotation_mode = 1
loop = false
tilt_enabled = false
[node name="Area3D" type="Area3D" parent="."]
[node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0194125, 2.2431, 4.34685)
shape = SubResource("BoxShape3D_uvh3q")

View File

@ -1,6 +1,7 @@
extends Area3D
class_name Character
signal turn(direction)
@export var path: Path3D:
set = set_path
@ -14,8 +15,8 @@ func _ready() -> void:
if path == null or path is not Path3D:
printerr("path is not set to a Path3D")
return
follow = path.get_node("Follow") as PathFollow3D
marker = follow.get_node("Marker") as Marker3D
follow = Utils.find_first_node_of_type(path, PathFollow3D) as PathFollow3D
marker = Utils.find_first_node_of_type(path, Marker3D) as Marker3D
func _process(delta: float):

View File

@ -12,15 +12,15 @@ func _ready() -> void:
if tiles.size() == 0:
printerr("There are no Tiles in the scene.")
return
change_distance = tiles[current_tile].length
#change_distance = tiles[current_tile].length
if character.path == null:
character.path = tiles[current_tile].path
func _process(delta: float) -> void:
if is_equal_approx(character.follow.progress, change_distance):
if is_equal_approx(character.follow.progress_ratio, 1):
current_tile += 1
if current_tile >= tiles.size():
return
character.path = tiles[current_tile].path
change_distance = tiles[current_tile].length
#change_distance = tiles[current_tile].length

View File

@ -10,7 +10,8 @@
script = ExtResource("1_oloil")
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(-0.827728, -0.0513662, 0.558773, 0.136568, 0.947417, 0.289396, -0.544256, 0.315852, -0.777189, 3.45982, 2.03445, -6.78341)
transform = Transform3D(0.763207, -0.546639, 0.344531, 0.296667, 0.770123, 0.564712, -0.574024, -0.328781, 0.749933, 3.45982, 2.03445, -6.78341)
shadow_enabled = true
[node name="Character" parent="." instance=ExtResource("1_nfwx6")]