+1 vote

My ladders have suddenly stopped working and I don’t know why. If there is something wrong with the climb state system lease point it out. I can post the 2d scenes if needed.
Thanks for the help!

extends KinematicBody2D (player script)


class_name Player

enum { MOVE, CLIMB }

var JUMP_FORCE = -160
var GRAVITY_FORCE = 3
var JUMP_RELEASE = -50
var MAX_SPEED = 100
var FRICTION = 15 # The Same
var ACCELERATION = 15 # The Same
var DOWNWARDS_ADDITIONAL_GRAVITY_FORCE = 4
var CLIMB_SPEED = 75
var DOUBLE_JUMP_COUNT = 1

var player_pos = self.position
var velocity = Vector2.ZERO
var state = MOVE
var double_jump = 1
var buffered_jump = false
var coyote_jump = false
var popun_on = false

export(Resource) var moveData = preload("res://FastPlayerMovementData.tres")

onready var animatedSprite = $AnimatedSprite
onready var ladderCheck = $LadderCheck
onready var jumpBufferTimer = $JumpBufferTimer
onready var coyoteJumpTimer = $CoyoteJumpTimer

func _ready():
    if Input.is_action_pressed("ui_up"):
        animatedSprite.play("Jump")
    moveData = moveData as PlayerMovementData
    self.position = Global.spawn_point

func _physics_process(delta):
    var input = Vector2.ZERO
    input.x = Input.get_axis("ui_left", "ui_right")
    input.y = Input.get_axis("ui_up", "ui_down")
    if state == MOVE: move_state(input)
    elif state == CLIMB: climb_state(input)

    # PauseStuff ------------------------------------------------------
#   if Input.is_action_just_pressed("ui_accept"):
#       get_tree().paused = true
#       $Popup.show()
#       popun_on = true
#   if Input.is_action_just_pressed("ui_down"):
#       get_tree().paused = false
#       $Popup.hide()
    #-------------------------------------------------------------------

func move_state(input):
    if is_on_ladder() and Input.is_action_just_pressed("ui_up"):
        state = CLIMB

    apply_gravity()
    if not horisontal_move(input):
        apply_friction()
        animatedSprite.animation = "idle"

    else:
        apply_acceleration(input.x)

        animatedSprite.flip_h = input.x < 0

        animatedSprite.flip_h = input.x < 0

    if is_on_floor():
        reset_double_jump()
    else:
        animatedSprite.animation = "Jump"

    if can_jump():
        input_jump()

    else:
        input_jump_release()
        input_double_jump()
        buffer_jump()
        fast_fall()

    var was_in_air = not is_on_floor()
    var was_on_floor = is_on_floor()
    velocity = move_and_slide(velocity, Vector2.UP)
    var just_landed = is_on_floor() and was_in_air
    if just_landed:
        animatedSprite.animation = "Run"
        animatedSprite.frame = 1

    var just_left_ground = not is_on_floor() and was_on_floor
    if just_left_ground and velocity.y >= 0:
        coyote_jump = true
        coyoteJumpTimer.start()

func climb_state(input):
    if not is_on_ladder():
        state = MOVE
    if input.length() != 0:
        animatedSprite.animation = "Climb"#LAdder Anim

    else:
        animatedSprite.animation = "ClimbIdle" #LAdder idle
    velocity = input * CLIMB_SPEED
    velocity = move_and_slide(velocity, Vector2.UP)

func player_died():
    self.position = Global.spawn_point


func is_on_ladder():
    if not ladderCheck.is_colliding(): return false
    var collider = ladderCheck.get_collider()
    if not collider is Ladder : return false
    return true

func input_jump_release():
    if Input.is_action_just_released("ui_up") and velocity.y < JUMP_RELEASE: 
        velocity.y = JUMP_RELEASE

func input_double_jump():
    if Input.is_action_just_pressed("ui_up") and double_jump > 0:
            velocity.y = JUMP_FORCE
            double_jump -= 1

func buffer_jump():
    if Input.is_action_just_pressed("ui_up"):
            buffered_jump = true
            jumpBufferTimer.start()

func fast_fall():
    if velocity.y > 0:
        animatedSprite.animation = "Falling"
        velocity.y += DOWNWARDS_ADDITIONAL_GRAVITY_FORCE

func horisontal_move(input):
    return input.x != 0

func can_jump(): 
    return is_on_floor() or coyote_jump

func reset_double_jump():
    double_jump = DOUBLE_JUMP_COUNT

func input_jump():
    if Input.is_action_just_pressed("ui_up") or buffered_jump: #jump
        velocity.y = JUMP_FORCE
        buffered_jump = false

func apply_gravity():
        velocity.y += GRAVITY_FORCE
        velocity.y = min(velocity.y, 300)

func apply_friction():
    velocity.x = move_toward(velocity.x, 0, FRICTION) 

func apply_acceleration(amount):
    animatedSprite.animation = "Run"
    velocity.x = move_toward(velocity.x, MAX_SPEED * amount, ACCELERATION) 

func _on_JumpBufferTimer_timeout():
    buffered_jump = false

func _on_CoyoteJumpTimer_timeout():
    coyote_jump = false

func load_owlet():
    animatedSprite.frames("res://PlayerOwlet.tscn")

func load_blue():
    animatedSprite.frames = load("res://PlayerBlueDude.tscn")

func _on_Hitbox_body_entered(body):
    player_died()
Godot version 3.5.1 (I think)
in Engine by (15 points)

It's going to be difficult for anyone to point out a specific problem in that amount of code.

That said, it looks like most of the ladder logic is depends heavily on the is_on_ladder() function. Is that working as expected? I'd start by adding some print statements there (and in other critical locations) to get some idea of where things are going wrong.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.