- Fri 29 Sep 2017, 23:57
One way to fix it is to create an object as wide as the platform, but very short e.g. 5 pixels high, that is continuously positioned with an event that puts it at Platform.Y()-5 i.e. it sits just above the platform. You can then check for a collision between this object and the player. If there is one it means the player is on the platform so the action adjusts Player.Y() to equal Platform.Y()-Player.Height(). It would probably be best to also have the condition that the jump key isn't being pressed. You would also hide the new object at the start of the scene.
This method should work fine if there is only one platform, but if you have several then it becomes more complicated.
An alternative is to reverse the process and have an invisible object always just under the player object, which can be collision checked with whatever the player is standing on and do the Player.Y() = Platform.Y()-Player.Height() action if it is colliding with a vertically moving platform.
For the second problem, I assume you'd prefer the platform to bounce back up off the player's head. You should be able to achieve this by checking for a player/platform collision and also checking if the Player.Y() value is bigger than the Platform.Y() value. If it is, the player is below the platform, so the action should then reverse the direction of the platform movement.