Compare commits

...

4 Commits

Author SHA1 Message Date
40b8d0a806 add initial slide animation 2024-10-20 16:33:47 -07:00
2bb8f23377 add initial jump mechanic 2024-10-13 14:49:58 -07:00
4a39252688 add auto generation of turns 2024-10-12 16:16:43 -07:00
0323cfb638 fix visuals for ramp tile 2024-10-12 15:44:33 -07:00
9 changed files with 199 additions and 48 deletions

View File

@ -36,6 +36,8 @@ func _ready() -> void:
func _process(delta: float) -> void:
if has_next_path():
paths[path_index+1].follow.v_offset = path.follow.v_offset
if is_equal_approx(follow.progress_ratio, 1) and has_next_path():
get_next_path().receive_marker(progress_marker)
path_index += 1

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=7 format=3 uid="uid://fafw4evt372"]
[gd_scene load_steps=8 format=3 uid="uid://fafw4evt372"]
[ext_resource type="Script" path="res://Tiles/tile.gd" id="1_qgvt0"]
[ext_resource type="PackedScene" uid="uid://dh2nm1sphyfqx" path="res://Tiles/TilePath.tscn" id="2_66bgp"]
@ -14,34 +14,55 @@ size = Vector2(10, 10)
material = SubResource("StandardMaterial3D_cwetn")
size = Vector2(2, 10)
[sub_resource type="PlaneMesh" id="PlaneMesh_hvfah"]
material = SubResource("StandardMaterial3D_cwetn")
size = Vector2(10, 11.685)
center_offset = Vector3(0, 0, -5.825)
[sub_resource type="Curve3D" id="Curve3D_8f65e"]
_data = {
"points": PackedVector3Array(0, 0, 0, 0, 0, 0, 0, 0.00492096, 0.00431776, 0, 0, 0, 0, 0, 0, 0, 4.99628, -8.66443),
"tilts": PackedFloat32Array(0, 0)
"points": PackedVector3Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -10, 0, 0, 0, 0, 0, 0, 0, 6, -20, 0, 0, 0, 0, 0, 0, 0, 6, -30),
"tilts": PackedFloat32Array(0, 0, 0, 0)
}
point_count = 2
point_count = 4
[node name="Tile1" type="Node3D"]
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, 2.48097, -4.33106)
transform = Transform3D(1, 0, 0, 0, 1, -2.38419e-07, 0, 2.38419e-07, 1, 0, 0, -5)
mesh = SubResource("PlaneMesh_jju0s")
[node name="Wall1" type="MeshInstance3D" parent="."]
transform = Transform3D(-4.37114e-08, 1, 0, -0.866025, -3.78552e-08, -0.5, -0.5, -2.18557e-08, 0.866025, -5, 3.347, -3.83106)
transform = Transform3D(-4.37114e-08, 1, -2.09725e-14, -1, -4.37114e-08, -2.38419e-07, -2.38419e-07, 8.88178e-15, 1, -5, 1, -5)
mesh = SubResource("PlaneMesh_rsriu")
[node name="Wall2" type="MeshInstance3D" parent="."]
transform = Transform3D(-4.37114e-08, 1, 0, -0.866025, -3.78552e-08, -0.5, -0.5, -2.18557e-08, 0.866025, 5, 3.347, -3.83106)
transform = Transform3D(-4.37114e-08, 1, -2.09725e-14, -1, -4.37114e-08, -2.38419e-07, -2.38419e-07, 8.88178e-15, 1, 5, 1, -5)
mesh = SubResource("PlaneMesh_rsriu")
[node name="Floor2" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 0.857167, -0.515038, 0, 0.515038, 0.857167, 0, 0, -10)
mesh = SubResource("PlaneMesh_hvfah")
[node name="Floor3" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, -2.38419e-07, 0, 2.38419e-07, 1, 0, 6, -25)
mesh = SubResource("PlaneMesh_jju0s")
[node name="Wall3" type="MeshInstance3D" parent="."]
transform = Transform3D(-4.37114e-08, 1, -2.09725e-14, -1, -4.37114e-08, -2.38419e-07, -2.38419e-07, 8.88178e-15, 1, -5, 7, -25)
mesh = SubResource("PlaneMesh_rsriu")
[node name="Wall4" type="MeshInstance3D" parent="."]
transform = Transform3D(-4.37114e-08, 1, -2.09725e-14, -1, -4.37114e-08, -2.38419e-07, -2.38419e-07, 8.88178e-15, 1, 5, 7, -25)
mesh = SubResource("PlaneMesh_rsriu")
[node name="SpawnPoint" type="Marker3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 4.95971, -8.6685)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 6, -30)
[node name="MainPath" parent="." instance=ExtResource("2_66bgp")]
curve = SubResource("Curve3D_8f65e")
[node name="OnScreenNotifier" type="VisibleOnScreenNotifier3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.38611, -4.31944)
aabb = AABB(-5, -3.36357, -4.43531, 10, 6.72714, 8.87062)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 4, -15)
aabb = AABB(-5, -4, -15, 10, 8, 30)

View File

@ -29,7 +29,7 @@ _data = {
}
point_count = 2
[sub_resource type="Curve3D" id="Curve3D_f5rtl"]
[sub_resource type="Curve3D" id="Curve3D_3qlkp"]
_data = {
"points": PackedVector3Array(0, 0, 0, 0, 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, 0, -5, 0, 0, 0, 0, 0, 0, 5, 0, -5),
"tilts": PackedFloat32Array(0, 0, 0)
@ -44,10 +44,11 @@ _data = {
point_count = 3
[sub_resource type="BoxShape3D" id="BoxShape3D_uvh3q"]
size = Vector3(9.80943, 5.486, 17.6183)
size = Vector3(9.809, 12, 17.618)
[node name="Tile1" type="Node3D"]
script = ExtResource("1_f1mql")
turn_direction = 1
[node name="Floor" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -5)
@ -68,7 +69,7 @@ curve = SubResource("Curve3D_r80si")
curve = SubResource("Curve3D_gpbgb")
[node name="PathRight" parent="." instance=ExtResource("2_yvi2s")]
curve = SubResource("Curve3D_f5rtl")
curve = SubResource("Curve3D_3qlkp")
[node name="PathLeft" parent="." instance=ExtResource("2_yvi2s")]
curve = SubResource("Curve3D_a3s3y")
@ -79,7 +80,7 @@ transform = Transform3D(1.31134e-07, 0, 1, 0, 1, 0, -1, 0, 1.31134e-07, -5, 0, -
[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, -0.65315)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0194125, 5.56203, -0.65315)
shape = SubResource("BoxShape3D_uvh3q")
[node name="Obstacle" parent="." instance=ExtResource("3_us011")]

View File

@ -36,7 +36,7 @@ _data = {
}
point_count = 3
[sub_resource type="Curve3D" id="Curve3D_jhtrd"]
[sub_resource type="Curve3D" id="Curve3D_febxw"]
_data = {
"points": PackedVector3Array(0, 0, 0, 0, 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, 0, -5, 0, 0, 0, 0, 0, 0, -5, 0, -5),
"tilts": PackedFloat32Array(0, 0, 0)
@ -44,10 +44,11 @@ _data = {
point_count = 3
[sub_resource type="BoxShape3D" id="BoxShape3D_uvh3q"]
size = Vector3(9.80943, 5.486, 17.6183)
size = Vector3(9.809, 12, 17.618)
[node name="Tile1" type="Node3D"]
script = ExtResource("1_wj6en")
turn_direction = 2
[node name="Floor" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -5)
@ -71,15 +72,15 @@ curve = SubResource("Curve3D_gpbgb")
curve = SubResource("Curve3D_f5rtl")
[node name="PathLeft" parent="." instance=ExtResource("3_e2l5m")]
curve = SubResource("Curve3D_jhtrd")
curve = SubResource("Curve3D_febxw")
[node name="SpawnPoint" type="Marker3D" parent="."]
transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 5, 0, 0)
transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 5, 0, -5)
[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, -0.65315)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0194125, 5.56203, -0.65315)
shape = SubResource("BoxShape3D_uvh3q")
[node name="Obstacle" parent="." instance=ExtResource("2_tnkvo")]

View File

@ -1,13 +1,22 @@
extends Tile
class_name TileTurn
enum Direction {
Forward,
Left,
Right,
Both
}
@export var turn_direction: Direction = Direction.Forward
@onready var area_3d: Area3D = $Area3D as Area3D
@onready var path_forward: TilePath = $PathForward as TilePath
@onready var path_right: TilePath = $PathRight as TilePath
@onready var path_left: TilePath = $PathLeft as TilePath
var connected: bool = false
var current_direction: String = "forward"
var current_direction: Direction = Direction.Forward
var character: Character
var on_main_path: bool:
@ -36,17 +45,20 @@ func load_path() -> void:
paths.append($PathForward)
func turn(direction: String) -> void:
func turn(direction: Direction) -> void:
if on_main_path:
var next_path: TilePath = get_path_by_direction(direction)
if next_path == null or (direction != turn_direction and direction != Direction.Both):
return
current_direction = direction
paths[path_index+1] = get_path_by_direction(current_direction)
paths[path_index+1] = next_path
func get_path_by_direction(direction: String) -> TilePath:
if direction == "forward" and path_forward != null:
func get_path_by_direction(direction: Direction) -> TilePath:
if direction == Direction.Forward and path_forward != null:
return path_forward
elif direction == "right" and path_right != null:
elif direction == Direction.Right and path_right != null:
return path_right
elif direction == "left" and path_left != null:
elif direction == Direction.Left and path_left != null:
return path_left
return null

View File

@ -1,28 +1,41 @@
extends Area3D
class_name Character
signal turn(direction: String)
signal turn(direction: TileTurn.Direction)
@export var speed: float = 10.0
@onready var animation_player: AnimationPlayer = $AnimationPlayer as AnimationPlayer
@export var speed: float = 20.0
@export var jump_height: float = 3
@export var tile: Tile
var total_distance: float = 0.0
var current_height: float = 0.0
var jump_tween: Tween
var fall_tween: Tween
var in_air: bool = false
var sliding: bool = false
func _ready() -> void:
animation_player.animation_finished.connect(_animation_finished)
if tile == null or tile is not Tile:
printerr("tile is not set to a Tile")
return
func _process(delta: float):
func _process(delta: float) -> void:
if tile == null:
return
if Input.is_action_just_pressed("ui_right"):
turn.emit("right")
turn.emit(TileTurn.Direction.Right)
if Input.is_action_just_pressed("ui_left"):
turn.emit("left")
turn.emit(TileTurn.Direction.Left)
if Input.is_action_just_pressed("ui_up"):
jump()
if Input.is_action_just_pressed("ui_down"):
slide()
global_position = tile.marker_position
global_rotation = tile.marker_rotation
@ -31,9 +44,10 @@ func _process(delta: float):
var travel: float = speed * delta
tile.follow.progress += travel
total_distance += travel
tile.follow.v_offset = current_height
func _on_area_entered(area):
func _on_area_entered(area: Area3D) -> void:
if area is Obstacle:
handle_obstacle(area)
@ -42,3 +56,33 @@ func handle_obstacle(obstacle: Obstacle) -> void:
if obstacle.effect == Obstacle.ObstacleEffect.Kill:
print("kill")
speed = 0
func jump() -> void:
if in_air or sliding:
return
in_air = true
jump_tween = get_tree().create_tween()
jump_tween.tween_property(self, "current_height", jump_height, 0.25).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_OUT)
jump_tween.tween_callback(fall)
func fall() -> void:
fall_tween = get_tree().create_tween()
fall_tween.tween_property(self, "current_height", 0, 0.25).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN)
fall_tween.tween_callback(finish_falling)
func finish_falling() -> void:
in_air = false
func slide() -> void:
if in_air or sliding:
return
sliding = true
animation_player.play("slide")
func _animation_finished(animation_name: String) -> void:
if animation_name == "slide":
sliding = false

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=4 format=3 uid="uid://vamte52rvfhy"]
[gd_scene load_steps=7 format=3 uid="uid://vamte52rvfhy"]
[ext_resource type="Script" path="res://character/character.gd" id="1_evtr0"]
@ -6,11 +6,59 @@
[sub_resource type="CapsuleMesh" id="CapsuleMesh_br0ui"]
[sub_resource type="Animation" id="Animation_3gdgw"]
resource_name = "slide"
length = 1.1
tracks/0/type = "rotation_3d"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("MeshInstance3D")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = PackedFloat32Array(0, 1, 0, 0, 0, 1, 0.0001, 1, 0, 0, 0, 1, 0.3, 1, 0.707107, 0, 0, 0.707107, 0.8, 1, 0.707107, 0, 0, 0.707107, 1.1, 1, 0, 0, 0, 1)
tracks/1/type = "position_3d"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("MeshInstance3D")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = PackedFloat32Array(0, 1, 0, 1, 0, 0.3, 1, 0, 0.511, 0.7, 0.8, 1, 0, 0.511, 0.7, 1.1, 1, 0, 1, 0)
tracks/2/type = "rotation_3d"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("CollisionShape3D")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = PackedFloat32Array(-2.23517e-08, 1, 0, 0, 0, 1, 9.99793e-05, 1, 0, 0, 0, 1, 0.3, 1, 0.707107, 0, 0, 0.707107, 0.8, 1, 0.707107, 0, 0, 0.707107, 1.1, 1, 0, 0, 0, 1)
tracks/3/type = "position_3d"
tracks/3/imported = false
tracks/3/enabled = true
tracks/3/path = NodePath("CollisionShape3D")
tracks/3/interp = 1
tracks/3/loop_wrap = true
tracks/3/keys = PackedFloat32Array(-2.23517e-08, 1, 0, 1, 0, 0.3, 1, 0, 0.511, 0.7, 0.8, 1, 0, 0.511, 0.7, 1.1, 1, 0, 1, 0)
[sub_resource type="Animation" id="Animation_tu0ui"]
length = 0.001
tracks/0/type = "rotation_3d"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("MeshInstance3D")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = PackedFloat32Array(0, 1, 0, 0, 0, 1)
[sub_resource type="AnimationLibrary" id="AnimationLibrary_w1708"]
_data = {
"RESET": SubResource("Animation_tu0ui"),
"slide": SubResource("Animation_3gdgw")
}
[node name="Character" type="Area3D"]
script = ExtResource("1_evtr0")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 5.21541e-08)
shape = SubResource("CapsuleShape3D_gnhao")
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
@ -21,4 +69,9 @@ skeleton = NodePath("")
[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)
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_w1708")
}
[connection signal="area_entered" from="." to="." method="_on_area_entered"]

View File

@ -7,6 +7,9 @@ var tile_index: int = 0
var run_started: bool = false
var tile_parent: Node
var character: Character
var min_turn: int = 3
var max_turn: int = 10
var turn_counter: int = randi_range(min_turn, max_turn)
var current_tile: Tile:
get = get_current_tile
@ -23,6 +26,8 @@ func _process(delta: float) -> void:
return
if tiles.size() < 15:
add_tile()
if has_next_tile():
tiles[tile_index+1].follow.v_offset = current_tile.follow.v_offset
if is_equal_approx(current_tile.follow.progress_ratio, 1) and has_next_tile():
if current_tile.has_next_path():
return
@ -35,9 +40,7 @@ func start_run(tile_parent: Node) -> void:
character = Utils.get_first_node_of_type(get_tree().root, Character) as Character
get_current_tiles()
if tiles.size() == 0:
var tile: Tile = generate_tile()
tiles.append(tile)
tile_parent.add_child(tile)
add_first_tile()
character.tile = current_tile
run_started = true
@ -48,17 +51,31 @@ func get_current_tiles() -> void:
tile.left_screen.connect(tile_left_screen, CONNECT_ONE_SHOT)
func generate_tile() -> Tile:
var index = randi_range(0, tile_set.strait_tiles.size()-1)
var tile_scene: PackedScene = tile_set.strait_tiles[index]
func generate_tile(tiles: Array[PackedScene]) -> Tile:
var index = randi_range(0, tiles.size()-1)
var tile_scene: PackedScene = tiles[index]
var tile: Tile = tile_scene.instantiate() as Tile
tile.left_screen.connect(tile_left_screen, CONNECT_ONE_SHOT)
return tile
func add_first_tile() -> void:
var tile: Tile = generate_tile(tile_set.strait_tiles)
tiles.append(tile)
tile_parent.add_child(tile)
tile.global_position = Vector3.ZERO
tile.global_rotation = Vector3.ZERO
func add_tile() -> void:
var last_tile: Tile = tiles[tiles.size()-1]
var tile: Tile = generate_tile()
var tile: Tile
if turn_counter <= 0:
tile = generate_tile(tile_set.turn_tiles)
turn_counter = randi_range(min_turn, max_turn)
else:
tile = generate_tile(tile_set.strait_tiles)
turn_counter -= 1
tiles.append(tile)
tile_parent.add_child(tile)
tile.global_position = last_tile.spawn_point.global_position

View File

@ -39,22 +39,22 @@ tile = NodePath("../Tile1")
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -10)
[node name="Tile3" parent="." instance=ExtResource("4_uxk3v")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.0861304, -19.3201)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -20)
[node name="Tile4" parent="." instance=ExtResource("3_vddfn")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 5, -27.9971)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 6, -50)
[node name="Tile5" parent="." instance=ExtResource("5_ynp1e")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 5, -37.9673)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 6, -60)
[node name="Tile6" parent="." instance=ExtResource("3_vddfn")]
transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 5.01222, 5, -42.9558)
transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 5, 6, -65)
[node name="Tile7" parent="." instance=ExtResource("5_ynp1e")]
transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 15.0122, 5, -42.9555)
transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 15, 6, -65)
[node name="Tile8" parent="." instance=ExtResource("3_vddfn")]
transform = Transform3D(-1, 0, 8.74228e-08, 0, 1, 0, -8.74228e-08, 0, -1, 20, 5, -37.9705)
transform = Transform3D(-1, 0, 8.74228e-08, 0, 1, 0, -8.74228e-08, 0, -1, 20, 6, -60)
[node name="Tile9" parent="." instance=ExtResource("6_327qh")]
transform = Transform3D(-1, 0, 8.74228e-08, 0, 1, 0, -8.74228e-08, 0, -1, 20, 5, -27.9764)
transform = Transform3D(-1, 0, 8.74228e-08, 0, 1, 0, -8.74228e-08, 0, -1, 20, 6, -50)