const SPEED = 300.0
const JUMP_VELOCITY = -400.0
const wall_jump_push_force = 300.0
const sawDamage = 15
const hazardDamage = 15
const wallGravity = 0
var deathBool = true #flips when player dies to break physics_process loop
enum States {IDLE, WALKING, FALLING, WALL_SLIDING, JUMPING}
var state: States = States.IDLE
var previousState: States = States.IDLE
func set_state(direction: float) -> void:
previousState = state
if is_on_wall_only():
state = States.WALL_SLIDING
elif direction !=0:
state = States.WALKING
else:
state = States.IDLE
#print("state IDLE")
#if not is_on_floor():
#state = States.FALLING
if Input.is_action_just_pressed("jump") and (is_on_floor() or is_on_wall()): #
state = States.JUMPING```
#Having issues implementing wall jumping and sliding
2 messages · Page 1 of 1 (latest)
#print(wallJumpCooldown.time_left)
check_charge() #checks player charge for game over
var direction := Input.get_axis("left", "right")
set_state(direction)
velocity += get_gravity() * delta
if state == States.IDLE:
if wallJumpCooldown.time_left == 0.0:
velocity.x = direction * SPEED
animatedSprite2d.play("idle")
elif state == States.JUMPING:
if previousState == States.WALL_SLIDING:
if rayCastLeft.is_colliding() and rayCastLeft.collider.name == "Foreground": #checks if colliding with wall
velocity.y = JUMP_VELOCITY #JUMPING STATE
velocity.x += 1 * wall_jump_push_force
print("WALL JUMP RIGHT")
elif rayCastRight.is_colliding() and rayCastRight.collider.name == "Foreground": #checks if colliding with wall
velocity.y = JUMP_VELOCITY #JUMPING STATE
velocity.x = -1 * wall_jump_push_force
print("WALL JUMP RIGHT")
wallJumpCooldown.start()
else:
velocity.y = JUMP_VELOCITY #JUMPING STATE
elif state == States.WALKING:
animatedSprite2d.flip_h = (direction ==-1) #flips animation WHEN WALKING STATE
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
animatedSprite2d.play("walking")
elif state == States.WALL_SLIDING and previousState != States.JUMPING:
if direction != 0:
velocity.x = direction * SPEED
#ADD SLOWER GRAVITY
animatedSprite2d.play("wall_sliding")