New Ladder Problems Question?

Godot Version

4.2.2

Question

Hello all,

I was following a ladder tutorial but it was for a game that was in progress and also for Godot 3.5, and in the end the collisions section just got too confusing and could not get in functioning correctly - I am fairly new to Godot and some of the knowledge in the tut was above me.

So, now I am trying it on my own and have run into some problem(s):

So far, I have a scene named “LaddersArea”, went to the Node tab and Groups and called it “ladders”:

And in-game it looks this:

The code I have used for the ladder is this:

extends Area2D

#access to player
@onready var player = $“…/Player”

func _on_body_entered(body):
print(“Ladder area entered”);
#access player setLadder() function
player.setLadder(true);
#pass # Replace with function body.

func _on_body_exited(body):
print(“Ladder area exited”);
player.setLadder(false);
#pass # Replace with function body.

and the code within the player “hero” for the purposes of “using” the ladder is this:

#now creating a var (bool???) to know if hero
#is “on” a ladder initially set to false
var on_ladder: bool = false;

#ladder set function
func setLadder(TFvalue):
on_ladder = TFvalue;

When the player “collides” with the ladder it sets the value to true, and prints the appropriate message, and vice versa, so, that appears to be working correctly.

What I need know is this all that needs to be done before coding movement? And what I need to do the start coding movement up/down the ladder? I don’t want someone to just give me a solution, this is supposed to be a learning exercise, but rather someone to give me a tips/pointers (no C++ pun intended) to get started on coding this. Like for instance, I have no climbing animations for the character I am using, so just looking for something to get the character moving up and down with the “idle” animation playing, handling velocity in the y direction and whether I can use the 2d collision shape with the Ladder as the basis for this. Another problem will be getting off a ladder, a problem for another date :grin:.

As always if you can help in anyway here is a big thankyou in advance.

Regards.

Sure this looks fine, the player code just need to use this on_ladder variable to switch it’s movement. where normally it would look for Left/Right inputs, if on_ladder is true it needs to respond to Up/Down inputs.

func _phsyics_process(delta: float) -> void:
    if on_ladder:
        if Input.is_action_pressed("UP"):
            velocity.y = -100
        # similar for down
    else:
        if Input.is_action_pressed("RIGHT"):
            velocity.x = 100
        # similar for left

That’s all it needs :hushed:, it can’t be that easy, surely. I’m sure there’s a kick to the head there somewhere. Anyway, I’ll see what happens when I try it out tomorrow and report back.

1 Like

Reporting back:

Now what you said worked as advertised, however, when I release the Up button say halfway up the ladder the hero drops back down to the platform below. Probably because the logic thinks I am in the air and applies gravity.

I can work with it as it is and place One Way entries to the platform above, but, I will try to play around with the gravity and see if I can stop the hero while on the ladder. This is the kick I was talking about :stuck_out_tongue_winking_eye:.

In any case thankyou, thankyou, THANK-YOU!!! For getting me past the last problem, I thought it would be insurmountable with my limited knowledge.

Regards.

PS: best I could do was setting velocity.y to zero meaning a very slow descent while on_ladder, however, I can live with that it’s not like I’ll be ever be selling this game. Using -16.3 as velocity when on ladder slows descent to almost nil. With a one way near the top of the ladder the hero slides down slowly till hitting the object and stops, something that I think is fine but no travelling back down.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.