Hello all,
I've been trying to implement moving platforms in Godot but have some special use cases for my game that I'm running into a wall against. In most cases I could set up a basic moving platform and have my player's velocity match it by applying the get_platform_velocity() function to my player's movement (and using that same value when he jumps to retain velocity). But I have an issue with ledge hanging on moving platforms.

My player body is a capsule using a CharacterBody3D node. The main case where I encounter my issus is when hanging from the corner of a moving platform, the collision body is not always going to maintain contact with the moving platform, causing get_platform_velocity() to be zero. The player will then detach from the platform and fall.

I have two separate solutions in mind for this and would love to hear any thoughts people have about these ideas:

1) Using a RemoteTransform3D:
When player enters a ledge hang state on a moving platform, dynamically create a RemoteTransform3D object in gdscript and pin the player directly to the platform. This is a bit finnicky to set up but if I could get the positioning right I could potentially have this work. I'm unsure the best way to get the player to detach from the RemoteTransform3D node when leaving the platform

2) Reparent the player as a child of the moving platform:
I'm unsure about this. It could work but taking something as major as the player and reparenting them at will seems like code smell or could have some adverse affects I'm not currently privy too later into my project.

  • xyz replied to this.

    Dekunutter If nothing can push the player when hanging on the ledge it means that they can't exit the ledge state unless told so by issuing a movement command. So don't check for contact at all once you enter the hanging state, until you exit the state.

      xyz Hey thanks for chiming in. I'm not sure thats exactly what I'm looking for. I'm not really concerned about the state transitions in/out of hanging. I'm trying to find a way to have the player move along with a platform that they technically arent standing on. Since I cant gaurantee collision I can't rely on get_platform_velocity(). I believe I can only get that value on a frame when the player is making some collision with the platform.

      If I was to just use values from the last frame that they had contact I'll see issues when the platform changes direction.

      • xyz replied to this.

        Dekunutter Yeah that's why you don't need to rely on collision once the player attaches to a platform. That's defacto state change and you should maintain a flag that reflects that state change.

        That makes sense ya! I have state transitions set up so its not just collision data that determines when to enter/exit hanging state but still having issues applying the moving platforms velocity to the player consistently each frame that they are in the hanging state

        • xyz replied to this.

          Dekunutter You don't actually need to apply velocity. Just set player's position to be the same as platform's position each frame. Of course add an offset calculated at the moment of attachment.

          Ya thanks thats a good point, makes it very simple. I struggled to see how I would handle left/right movement while hanging using that method since I want the player to not just be hanging staticly. I'd probably need to calculate the offset at the end of each frame perhaps so that it accounts for any adjustment applied by move_and_slide(). Might not be on the right track with that thought but something to try later.

          I did end up getting something equivalent working with velocities since my last post, but the key was that moving platforms need to be higher up in the node tree than the player so that they update physics updates run before the player's phyiscs_process() is invoked. I alternatively also got it working by reparenting the player as a child of the moving platform while hanging from it but not sure that's a route I want to take.

          • xyz replied to this.

            Dekunutter Yeah temporarily parenting the player might be viable option as well. It's not without its own possible gotchas though 🙂