Jumping On Raising Platform

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: 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

CircleBot | 2020-01-17 04:40

:bust_in_silhouette: Reply From: 439Games

Hello, i was stuck at the same problem. So from this post and another post from https://godotforums.org/discussion/19024/how-to-get-vertical-moving-platforms-lifts-to-work-in-2d I find a working solution that suit well for my moving up-down platform.

So I will share my solution to be able to jump when the platform was rising up.

My Player movement was done in func _physics_process(delta) with the move_and_slide(velocity, Vector2.UP) method.

I manually force the Player to not touching the moving up platform when he jump by tweaking his position.y

After my Jump i put this code:

if get_floor_velocity().y < 0:
	position.y += get_floor_velocity().y * get_physics_process_delta_time() - gravity * get_physics_process_delta_time() - 1

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.