[2D]Jump in arc with one input

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Vetern

I’m trying to make a player jump in an arc with one imput (left or right in this case).
I couldn’t find a way to make the player move horizontally as he goes up and down (with gravity and jump_h as const), it only teleports or move just a little.

Hi, What node are you using for the player? I think the best option is to use KinematicBody2D with velocity of type Vector2() parameter, and in _input() check when an input is pressed. Then you modify both y and x velocity according to the key pressed, and set an animation. Yo can prevent user for using another key until the animation finished. If this is what you need i could give you a more elaborated example with code.

p7f | 2018-11-23 19:03

:bust_in_silhouette: Reply From: flurick

I would add a variable for left/right velocity, adding it to the position over every frame while reducing the variable for left/right.

process():
position.x += leftright_velocity
leftright_velocity *= 0.9