I’ve been bashing my head against this issue for hours, time to ask for help…
I’m making a derivative of Hoppy Days, with moving platforms, some of which move up and down vertically.
The problem: when player character (PC) lands on a vertical motion platform while the platform is moving up, it gets vertically stuck and can’t jump off it. PC can, however, walk off it. When trying to jump, the audioplayer (implemented as in Hoppy Days) makes a buzzing sound, as if trying to play, then terminating.
Some constraints, and other potentially relevant info:
Player should move along with platform while idle on it. As of now, I’ve tried implementing this through platform collision detection, with a callback to the player, passing platform node as argument, and player updating its motion vector as platform velocity in every physics_process() call. I’ve commented this functionality out, and bug still there.
Player should be unaffected by player movement.
Platform needs collision detection. Platform locations and movement directions are procedurally (semi-randomly) generated, and reverse direction when colliding with anything except PC.
Level is implemented as an “arena”, totally enclosed by floors, walls, and ceiling. Game is intended for very young children - no losing lives or falling off the world. I have implemented arena walls as StaticBody2D.
What I’ve tried so far:
Implemented MovingPlatform as:
– StaticBody2D, decorated with Area2D for collision detection. Exhibits jump bug as described.
– Area2D. PC simply falls through - I can’t seem to make the PC move along with the platform.
– KinematicBody2D, decorated with Area2D. Platforms stick to floor of arena. Can’t seem to get it to reverse direction.
– RigidBody2D. Many undesired behaviors. Pretty sure this is not the way to go, as I don’t want the platform itself affected by the physics engine.
Some tweaks to player mechanics:
– When trying to jump, move player slightly up first, then add velocity.
– Setting PC collision safety margin low (0.01)
I saw a potentially related thread here on the forum, but I didn’t see a conclusive solution. Anybody have a clear solution to setting this up properly?
MovingPlatform.gd (in last-tried implementation as Area2D; code essentially the same with the other variants, with signal-processing function names changed appropriately)
Made the MovingPlatform a StaticBody2D. Used code to move it around. Used StaticBody2D method “set_constant_linear_velocity(velocity)” to set its affecting velocity to whatever direction and speed the platform is actually moving in.
When PC is on a platform moving up and is attempting to jump, first set its position.y a few pixels (I used 10) higher and then apply the jump velocity vector. The original 1 pixel was not cutting it. I think the issue is that the player’s collision shape was getting “stuck” in the platform’s collision shape (because of the latter moving up) - not sure why that is; Godot’s collision detection and move_and_slide() and is_on_floor() may be slightly bugged somehow. Anyways, with fix #1 above, I’m not sure this one was necessary, but I applied this one first and it seemed to work so I didn’t futz with it anymore. I still needed fix #1 to get the PC moving with the platform (at least horizontally).