Topic was automatically imported from the old Question2Answer platform.
Asked By
CircleBot
Hello, i have some problem and need help to find its solution. I want to make my player character to jump on platform that moving upward.
Each time i press jump key the character won’t jump, I think this is because the vertical movement cannot catch up with is_on_floor checking that happened in _physic_process
So far i have used KinematicBody2D,StaticBody2D, Tween and AnimationPlayer to control player movement, but none of them work. Also doubling the jump speed didn’t work too, i even erasing the is_on_floor line, and it still not working.
Looking at Godot Platformer2D project demo, it has this problem too. So i want to know if there is a solution for this problem?
Have you figured this out yet? I’m having the same issue. When jumping the playing sticks to the platform. I tried using slide with snap but that still won’t work.
Pmanpa | 2020-01-06 15:47
Yes, I just put another moveandslide after condition get_floor_velocity.y < 0 is met and that code is put at the end of physic process code block. Not really a solution but its working
Ok, let me explain this code, im not a pro so i will do my best.
get_floor_velocity return the velocity from the floor you are on. A moving up platform will have a negative velocity.y
So the floor is moving up and we want to give a small artificial push to the Player (position.y +=) to be sure when he jump he suddently not touching anymore the floor. But we dont want give a too big push for nothing, just the smallest one to be sure to avoid sticking on the moving platform when we jump.
I want to know how many pixel the platform was going up for the next frame. I got it with get_floor_velocity().y * get_physics_process_delta_time()
gravity is my variable to apply my gravity(in my case gravity = 15). So i substract it to get the right calculation to got the amount of pixel my Player need to not be on the platform anymore after jumping.
The - 1 is a magic number for safety. You can increase to - 2, - 3 but for my test, all work well with just - 1.