add initial jump mechanic

This commit is contained in:
Matthew Welch 2024-10-13 14:49:58 -07:00
parent 4a39252688
commit 2bb8f23377
6 changed files with 78 additions and 17 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=11 format=3 uid="uid://c0xv7v6ako25a"]
[gd_scene load_steps=12 format=3 uid="uid://c0xv7v6ako25a"]
[ext_resource type="Script" path="res://Tiles/tile_turn.gd" id="1_f1mql"]
[ext_resource type="PackedScene" uid="uid://dh2nm1sphyfqx" path="res://Tiles/TilePath.tscn" id="2_yvi2s"]
@ -29,6 +29,13 @@ _data = {
}
point_count = 2
[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)
}
point_count = 3
[sub_resource type="Curve3D" id="Curve3D_a3s3y"]
_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),
@ -37,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)
@ -60,6 +68,9 @@ curve = SubResource("Curve3D_r80si")
[node name="PathForward" parent="." instance=ExtResource("2_yvi2s")]
curve = SubResource("Curve3D_gpbgb")
[node name="PathRight" parent="." instance=ExtResource("2_yvi2s")]
curve = SubResource("Curve3D_3qlkp")
[node name="PathLeft" parent="." instance=ExtResource("2_yvi2s")]
curve = SubResource("Curve3D_a3s3y")
@ -69,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

@ -1,4 +1,4 @@
[gd_scene load_steps=11 format=3 uid="uid://b88nuwe42bhc1"]
[gd_scene load_steps=12 format=3 uid="uid://b88nuwe42bhc1"]
[ext_resource type="Script" path="res://Tiles/tile_turn.gd" id="1_wj6en"]
[ext_resource type="PackedScene" uid="uid://dkcjoccsgbggg" path="res://obstacles/Obstacle.tscn" id="2_tnkvo"]
@ -36,11 +36,19 @@ _data = {
}
point_count = 3
[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)
}
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)
@ -63,13 +71,16 @@ curve = SubResource("Curve3D_gpbgb")
[node name="PathRight" parent="." instance=ExtResource("3_e2l5m")]
curve = SubResource("Curve3D_f5rtl")
[node name="PathLeft" parent="." instance=ExtResource("3_e2l5m")]
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, -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,20 +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:
if next_path == null or (direction != turn_direction and direction != Direction.Both):
return
current_direction = 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,12 +1,17 @@
extends Area3D
class_name Character
signal turn(direction: String)
signal turn(direction: TileTurn.Direction)
@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
func _ready() -> void:
@ -15,14 +20,16 @@ func _ready() -> void:
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()
global_position = tile.marker_position
global_rotation = tile.marker_rotation
@ -31,6 +38,7 @@ 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):
@ -42,3 +50,21 @@ func handle_obstacle(obstacle: Obstacle) -> void:
if obstacle.effect == Obstacle.ObstacleEffect.Kill:
print("kill")
speed = 0
func jump() -> void:
if in_air:
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

View File

@ -26,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