Hi All!

Sorry, I'm very new to both Godot and Programming in general and this has me stumped.

I'm making a 2d Platformer and I want to be able to hold a button to make the player stick to the sides/bottoms of moving platforms (and move with them just like they were standing on top of it). I have searched for hints but everything I find is pre Godot 4 and isn't really what I'm looking for.

Currently, I have a working moving platform that I can stand on using CollisionShape2d and AnimationPlayer.

Any help would be very much appreciated!

using an animationplayer I don't know if I can, instead if you tell it to move using code through either a line2d(telling it to follow the line ) or even two elements(can be position2d or area2d ), located at each of the ends of which you want to lower the platform(very rough), sorry for some error in the syntax of my answer I am translating

    el_malo
    Thanks for replying! I'm sorry, I don't fully understand. Is there a way to make the player move along with the platform from to Side or Bottom if I use Area2d to move the platform?

      JordyBoy with an Area? No, but the player (assuming they're some kind of body) will interact with another body, even when moved with the animation player.

      However, this may not produce the desired results (the player may 'slide'), but this depends on what you want for your game. If you want them to stick, the simplest way to ensure this happens is to parent the player to the platform.

        spaceyjase

        Hi SpaceyJase,

        Thank you! I've been having that sliding problem you mentioned. Parenting is a good idea! Is there a way to make the platform a temporary parent to the player on collision from within the player script? I'm having trouble finding it if so. Maybe I'm way off...

        Either way thank you again for your response and help!!

          JordyBoy you could re-parent on collision but I really think it's unnecessary if the player is a RigidBody and the moving platform is another body, e.g. KinematicBody; they will interact correctly, especially if, on the platform body itself, you enable 'sync to physics'. Here's a quick demo I knocked up:

          The player is a RigidBody2D while the platform is being moved with a tween (but an animation also works), and is a KinematicBody2D. That's it, really simple.

          edit: Sorry, was in 3.5 mode. KinematicBody2D -> AnimatableBody2D.

          Wow thank you! I wasn't expecting a demo! That's really above and beyond.

          The issue I run into is when I want to stick to the side and/or bottom of the moving platform and still move with it. I want to set my velocity.x and my velocity.y to whatever that platforms velocity is but I can't seem to figure it out.

          Sorry for all of the trouble.

            JordyBoy Ah, okay - I somehow missed the side and/or bottom of the platform. Re-parenting might still be a viable option but you'd also have to stop the body responding to physics; rather, change its gravity so it is in the direction of the platform (and I'd assume perhaps left/right movement if 'sticking' to the bottom - but that's up to you!). This way, the physics still apply.