So I am making a 3D game with platforms moving diagonally, horizontally and vertically. Whenever my player collides with a platform and it’s velocity.y is equal to 0 for 2 consecutive frames, the player object becomes a child to the platform so that it moves with the platform but it can also move on the platform.
So far so good, it works perfectly on horizontal platforms and platforms moving upwards. However, if the player object falls down on a platform moving downwards it velocity.y doesn’t reach -0 so it doesn’t stick to the platform and I get this ugly bouncy effect where the cube(player.object) falls to the platform, stops, the platform continues, the cube falls again and so on.
One way to fix this is to remove the condition for velocity.y == 0 for 2 consecutive frames and instead check it in a single frame. But doing it this way will make it possible for the player to stick with the platform even when touching it from below the platform. For example, the platform is coming downwards towards the player, the player jumps and touches the bottom of the platform, its velocity.y is nullified and the player becomes a child of the platform. This is a scenario we want to avoid.
Any ideas how to fix this?