# Parabolic Jump Libgdx Without Box2D and With Vectors

I have tried to write a jump method that sketches out a parabolic jump but it results in either no movement, or a jerky upward movement when I try to scale up dt. I have the following things defined:

    x = 0;
y = 250;
pos.set(x, y); // position of player
velocity.set(2, 12); // player velocity
gravity.set(0, -2); // player gravity


Then I have the key input processor:

private void handleInput(float dt)
{
if(Gdx.input.isKeyPressed(Keys.D))
x += velocity.x;

if(Gdx.input.isKeyPressed(Keys.A))
x -= velocity.x;

if(Gdx.input.isKeyJustPressed(Keys.W))
jump(dt);

pos.set(x, y);
bound.setPosition(pos);
}


This is the jump method which takes in a Gdx delta time method:

private void jump(float dt)
{
y += velocity.y * dt;
velocity.set(velocity.x, velocity.y + gravity.y);

pos.set(x, y);
bound.setPosition(pos);
}


This is all called in the update method which is called once per frame in the render method:

public void update(float dt)
{
handleInput(dt);
movement(dt);
collision(dt);
}

• Please note that you can edit your questions, instead of deleting & reposting them. Frequently posting & deleting questions can trigger some of the site's automated anti-spam measures, so editing is usually your best bet. ;) Jan 20 '19 at 21:52
• @DMGregory oh okay, my bad. I've been a long time reader but I just started posting, thank you for the tips. Jan 20 '19 at 22:24

Here I created jump function which increases velocity toward upwards. Movement function, on the other hand, updates sprite(the player)'s position each frame. Trick is movement function uses velocity multiplied with Time Delta (seconds between each frame) to calculate position on the next frame.

• movement function runs every frame, so it goes in main loop.
• jump is called once (and must be only once) key is pressed, not each frame while key is pressed.

Gravity is there always, decreases vertical velocity each frame.

private void jump(float dt)
{
velocity.set(velocity.x, velocity.y + jumpPower);//define   jumpPower in your code
}

public void movement(float dt) //I believe should you have this
{
pos.set(x + (velocity.x * dt), y + (velocity.y * dt));//set position every frame
bound.setPosition(pos); //?set sprite position (not sure)
velocity.set(velocity.x, velocity.y * dt * gravityPower)//decrease vertical velocity every frame
}

• This is a good start for an answer, a bit more explanation would help!
– Almo
Mar 2 '19 at 5:14
• @Almo please let me know if it's improved Mar 2 '19 at 18:21

It could be that you only update the 'y' velocity when you call jump. Try updating 'y' every frame. Then when you call jump just increase the 'y' velocity.