Update typing
Add Tile class
This commit is contained in:
parent
0ebd3f2de3
commit
05d285a750
17
Tiles/Tile.gd
Normal file
17
Tiles/Tile.gd
Normal file
@ -0,0 +1,17 @@
|
||||
extends Node3D
|
||||
class_name Tile
|
||||
|
||||
|
||||
@onready var path = $MainPath as Path3D
|
||||
@onready var follow = $MainPath/Follow as PathFollow3D
|
||||
|
||||
var length: float:
|
||||
get:
|
||||
return path.curve.get_baked_length() as float
|
||||
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
func _process(delta):
|
||||
pass
|
@ -1,4 +1,6 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://cvtgigpmwwv4g"]
|
||||
[gd_scene load_steps=6 format=3 uid="uid://cvtgigpmwwv4g"]
|
||||
|
||||
[ext_resource type="Script" path="res://Tiles/Tile.gd" id="1_wu32c"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_cwetn"]
|
||||
cull_mode = 2
|
||||
@ -19,6 +21,7 @@ _data = {
|
||||
point_count = 2
|
||||
|
||||
[node name="Tile1" type="Node3D"]
|
||||
script = ExtResource("1_wu32c")
|
||||
|
||||
[node name="Floor" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("PlaneMesh_jju0s")
|
||||
@ -31,10 +34,10 @@ 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="Path3D" type="Path3D" parent="."]
|
||||
[node name="MainPath" type="Path3D" parent="."]
|
||||
curve = SubResource("Curve3D_q1k88")
|
||||
|
||||
[node name="PathFollow3D" type="PathFollow3D" parent="Path3D"]
|
||||
[node name="Follow" type="PathFollow3D" parent="MainPath"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 5)
|
||||
rotation_mode = 1
|
||||
loop = false
|
||||
|
@ -1,4 +1,6 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://fafw4evt372"]
|
||||
[gd_scene load_steps=6 format=3 uid="uid://fafw4evt372"]
|
||||
|
||||
[ext_resource type="Script" path="res://Tiles/Tile.gd" id="1_qgvt0"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_cwetn"]
|
||||
cull_mode = 2
|
||||
@ -19,7 +21,7 @@ _data = {
|
||||
point_count = 2
|
||||
|
||||
[node name="Tile1" type="Node3D"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)
|
||||
script = ExtResource("1_qgvt0")
|
||||
|
||||
[node name="Floor" type="MeshInstance3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.866025, -0.5, 0, 0.5, 0.866025, 0, 0.0893164, -0.333333)
|
||||
@ -33,10 +35,10 @@ 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="Path3D" type="Path3D" parent="."]
|
||||
[node name="MainPath" type="Path3D" parent="."]
|
||||
curve = SubResource("Curve3D_q1k88")
|
||||
|
||||
[node name="PathFollow3D" type="PathFollow3D" parent="Path3D"]
|
||||
[node name="Follow" type="PathFollow3D" parent="MainPath"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -2.40419, 3.96713)
|
||||
rotation_mode = 1
|
||||
loop = false
|
||||
|
@ -1,4 +1,6 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://b88nuwe42bhc1"]
|
||||
[gd_scene load_steps=6 format=3 uid="uid://b88nuwe42bhc1"]
|
||||
|
||||
[ext_resource type="Script" path="res://Tiles/Tile.gd" id="1_6m2c8"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_cwetn"]
|
||||
cull_mode = 2
|
||||
@ -19,6 +21,7 @@ _data = {
|
||||
point_count = 3
|
||||
|
||||
[node name="Tile1" type="Node3D"]
|
||||
script = ExtResource("1_6m2c8")
|
||||
|
||||
[node name="Floor" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("PlaneMesh_jju0s")
|
||||
@ -31,10 +34,10 @@ 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="Path3D" type="Path3D" parent="."]
|
||||
[node name="MainPath" type="Path3D" parent="."]
|
||||
curve = SubResource("Curve3D_q1k88")
|
||||
|
||||
[node name="PathFollow3D" type="PathFollow3D" parent="Path3D"]
|
||||
[node name="Follow" type="PathFollow3D" parent="MainPath"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 5)
|
||||
rotation_mode = 1
|
||||
loop = false
|
||||
|
@ -14,18 +14,18 @@ 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")
|
||||
marker = follow.get_node("Marker")
|
||||
follow = path.get_node("Follow") as PathFollow3D
|
||||
marker = follow.get_node("Marker") as Marker3D
|
||||
|
||||
|
||||
func _process(delta):
|
||||
func _process(delta: float):
|
||||
if path == null:
|
||||
return
|
||||
global_position = marker.global_position
|
||||
global_rotation = marker.global_rotation
|
||||
if follow.progress_ratio >= 1:
|
||||
return
|
||||
var travel = speed * delta
|
||||
var travel: float = speed * delta
|
||||
follow.progress += travel
|
||||
total_distance += travel
|
||||
|
||||
@ -35,14 +35,14 @@ func set_path(new_path: Path3D):
|
||||
printerr("path must be a Path3D")
|
||||
return
|
||||
path = new_path
|
||||
follow = Utils.find_first_node_of_type(path, PathFollow3D)
|
||||
follow = Utils.find_first_node_of_type(path, PathFollow3D) as PathFollow3D
|
||||
if follow == null:
|
||||
follow = PathFollow3D.new()
|
||||
path.add_child(follow)
|
||||
marker = Marker3D.new()
|
||||
follow.add_child(marker)
|
||||
return
|
||||
marker = Utils.find_first_node_of_type(follow, Marker3D)
|
||||
marker = Utils.find_first_node_of_type(follow, Marker3D) as Marker3D
|
||||
if marker == null:
|
||||
marker = Marker3D.new()
|
||||
follow.add_child(marker)
|
||||
|
@ -11,6 +11,7 @@ config_version=5
|
||||
[application]
|
||||
|
||||
config/name="Fantasy Run"
|
||||
run/main_scene="res://world.tscn"
|
||||
config/features=PackedStringArray("4.3", "Mobile")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
|
12
utils.gd
12
utils.gd
@ -1,17 +1,17 @@
|
||||
extends Node
|
||||
|
||||
func find_first_node_of_type(node: Node, type: Variant):
|
||||
func find_first_node_of_type(node: Node, type: Variant) -> Node:
|
||||
for child in node.get_children():
|
||||
if is_instance_of(child, type):
|
||||
return child
|
||||
return null
|
||||
|
||||
|
||||
func get_nodes_of_class(node: Node, type: Variant) -> Array:
|
||||
var nodes = []
|
||||
for child in node.get_children(true):
|
||||
func get_nodes_of_class(node: Node, type: Variant, include_internal: bool = false) -> Array[Variant]:
|
||||
var nodes: Array[Variant] = []
|
||||
for child in node.get_children(include_internal):
|
||||
if is_instance_of(child, type):
|
||||
nodes.append(child)
|
||||
elif child.get_child_count(true) > 0:
|
||||
nodes.append_array(get_nodes_of_class(child, type))
|
||||
elif child.get_child_count(include_internal) > 0:
|
||||
nodes.append_array(get_nodes_of_class(child, type, include_internal))
|
||||
return nodes
|
||||
|
25
world.gd
25
world.gd
@ -1,27 +1,26 @@
|
||||
extends Node3D
|
||||
|
||||
@onready var path: Path3D = $Path
|
||||
@onready var character: Character = $Character
|
||||
@onready var character = $Character as Character
|
||||
|
||||
var change_distance: float
|
||||
var paths: Array
|
||||
var current_path: int = 0
|
||||
var tiles: Array[Tile]
|
||||
var current_tile: int = 0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
paths = Utils.get_nodes_of_class(self, Path3D)
|
||||
if paths.size() == 0:
|
||||
printerr("There are no Path3Ds in the scene.")
|
||||
tiles.assign(Utils.get_nodes_of_class(self, Tile))
|
||||
if tiles.size() == 0:
|
||||
printerr("There are no Tiles in the scene.")
|
||||
return
|
||||
change_distance = paths[current_path].curve.get_baked_length()
|
||||
change_distance = tiles[current_tile].length
|
||||
if character.path == null:
|
||||
character.path = paths[current_path]
|
||||
character.path = tiles[current_tile].path
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if is_equal_approx(character.follow.progress, change_distance):
|
||||
current_path += 1
|
||||
if current_path >= paths.size():
|
||||
current_tile += 1
|
||||
if current_tile >= tiles.size():
|
||||
return
|
||||
character.path = paths[current_path]
|
||||
change_distance = paths[current_path].curve.get_baked_length()
|
||||
character.path = tiles[current_tile].path
|
||||
change_distance = tiles[current_tile].length
|
||||
|
Loading…
Reference in New Issue
Block a user