fall.gd
extends State
@onready var player: CharacterBody2D
var GRAVITY = 1800
var speed = 280
var acceleration = 1000
func enter() -> void:
player = state_machine.get_parent()
# Called when the node enters the scene tree for the first time.
func physics_update(_delta: float) -> void:
print("fall")
player.velocity.y += GRAVITY * _delta
player.velocity.x = move_toward(player.velocity.x, player.direction * speed, acceleration * _delta)
if player.is_on_floor() and !player.velocity.x == 0:
state_machine.change_state("move")
elif player.is_on_floor():
state_machine.change_state("idle")
if player.is_on_wall() and player.can_wall_slide == true and player.velocity.y <0:
state_machine.change_state("wall")
wall.gd
extends State
var acceleration = 8000
var speed = 250
@onready var player: CharacterBody2D
var GRAVITY = 1000
func enter() -> void:
player = state_machine.get_parent()
player.velocity.y = 0
func physics_update(delta: float) -> void:
print("wall")
player.velocity.x = move_toward(player.velocity.x, player.direction * speed, acceleration * delta)
player.velocity.y += 50 * delta
if player.wall_timer_started == false:
player.wall_timer_started = true
$"../../Timers/on_wall".start()
if player.can_wall_slide == false:
state_machine.change_state("fall")
if player.is_on_floor() and player.velocity.y >= 0:
state_machine.change_state("move")
if not player.is_on_wall():
state_machine.change_state("fall")
func _on_on_wall_timeout() -> void:
player.can_wall_slide = false
This is in both idle and move.gd
func enter() -> void:
player = state_machine.get_parent()
player.can_wall_slide = true
player.wall_timer_started = false
func physics_update(delta: float) -> void:
player.can_wall_slide = true
player.wall_timer_started = false
Im a newie and super confused
I want the character to slide on the wall for about 2 seconds and resets when lands on the floor But sometimes after landing on the fall it dosnt work