Skip to content

Commit

Permalink
transitions to wall run
Browse files Browse the repository at this point in the history
  • Loading branch information
ninetailsrabbit committed Dec 22, 2024
1 parent 4725b88 commit 8d0b450
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ func _ready() -> void:

finite_state_machine.register_transitions([
WalkToRunTransition.new(),
RunToWalkTransition.new()
RunToWalkTransition.new(),
JumpToWallRunTransition.new(),
FallToWallRunTransition.new()
])

finite_state_machine.state_changed.connect(on_state_changed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ actor = NodePath("../../..")
[node name="WallRun" type="Node" parent="FiniteStateMachine/Special" node_paths=PackedStringArray("actor")]
script = ExtResource("14_2jtjm")
actor = NodePath("../../..")
gravity_force = 0.6

[node name="StandCollisionShape" type="CollisionShape3D" parent="."]
shape = SubResource("CapsuleShape3D_1od8w")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ func ready():


func enter():
wall_run_start_cooldown_timer.start()

apply_jump()
actor.move_and_slide()

Expand Down Expand Up @@ -100,6 +98,8 @@ func physics_update(delta: float):


func apply_jump() -> void:
wall_run_start_cooldown_timer.start()

last_jumped_position = actor.position
jump_count += 1

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
class_name WallRun extends AirState

@export_category("Camera")
@export_range(0, 360.0, 0.01) var camera_rotation_angle: float = 5.0
@export_range(0, 360.0, 0.01) var camera_lerp_rotation_factor: float = 8.0
@export_category("Parameters")
@export var wall_speed: float = 5.0
@export var reduce_speed_gradually: bool = true
## The friction rate to reduce speed gradually on each frame multiplied by delta
@export var friction_to_reduce_speed: float = 0.1
## Reduce the velocity of the run based on this friction coeficient
@export var wall_friction: float = 0.2
## Set to zero to not have a limited time on wall running.
Expand All @@ -12,7 +20,7 @@ var current_wall_direction: Vector3 = Vector3.ZERO
var current_wall_normal: Vector3 = Vector3.ZERO
var wall_run_timer: Timer
var wall_run_cooldown_timer: Timer

var decrease_rate: float = 0.0

func ready() -> void:
_create_wall_run_timers()
Expand All @@ -29,8 +37,15 @@ func enter() -> void:
if wall_run_time > 0 and is_instance_valid(wall_run_timer):
wall_run_timer.start(wall_run_time)

print(current_wall_normal)
print(current_wall_direction)


func physics_update(delta: float) -> void:
actor.camera.rotation.z = lerp_angle(
actor.camera.rotation.z,
camera_rotation_angle * 1 if current_wall_normal.is_equal_approx(Vector3.LEFT) else -1,
delta * camera_lerp_rotation_factor
)



func exit(_next_state: MachineState) -> void:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class_name FallToWallRunTransition extends MachineTransition


func should_transition() -> bool:
if from_state is Fall:
return from_state.wall_run_start_cooldown_timer.is_stopped()

return true


func on_transition() -> void:
if from_state is Fall and to_state is WallRun:
from_state.wall_run_start_cooldown_timer.stop()
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class_name JumpToWallRunTransition extends MachineTransition


func should_transition() -> bool:
if from_state is Jump:
return from_state.wall_run_start_cooldown_timer.is_stopped()

return true


func on_transition() -> void:
if from_state is Jump and to_state is WallRun:
from_state.wall_run_start_cooldown_timer.stop()

0 comments on commit 8d0b450

Please sign in to comment.