on_body_entered and on_body_exited cancel each other

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By keidav

I have a Kinematic2D body that is my player, I have an Area2D that is a ladder (tiles represent the actual ladder, with one-way collision objects for the rungs that was converted in to a tileset). I can make the player climb the ladder, but not optionally walk past it.

Using print statements I can see that the on_body_entered gets called and is immediately followed by a on_body_exited when the player touches the ladder body. In effect cancelling each other. I was also hoping to use the collision layer to turn off the player layer allowing him to walk by the ladder.

Any code that can show how to walk past or optionally climb a ladder? I am at a loss, my code is a mess so I won’t post it as it will just confuse you :stuck_out_tongue:

Thanks in advance and I am happy to supply more info…

:bust_in_silhouette: Reply From: ponponyaya

I think the better way is to make an state machine, but it’s hard for beginner.
Anyway, you still have easier way to do that, take a look at this video.

P.S. If you want more information about the basic platform behavior. This is another video made by the same person.

I had built my ladder pretty close to what was in one of the videos and using state. My problem was with the Area2D collision layer. I moved it to another layer different from the player and everything functioned as expected.

keidav | 2022-03-02 00:41

Good Job! If you want to know more information about collision layer. You can take a look at this two videos( video1, video2). I got some great new ideas when I first saw those video.

ponponyaya | 2022-03-02 02:29

Thanks for the pointers!

keidav | 2022-03-02 02:50