0
votes

I am creating a character which moves, it moves upwards fine but when it moves side ways it is extremly slow. Here is the movement code:

p.getPosition().y += playerSpeed;

This is the code for handling input:

World world;

Player p;

WorldHandler wh;

public boolean touchUp(int screenX, int screenY, int pointer, int button) 
{
    p = world.getPlayer();

    wh = new WorldHandler(world);

    if(screenX >= Gdx.graphics.getWidth() / 2) // Right side of the screen
    {
        p.getVel().x = wh.playerSpeed;
    }

    if(screenX <= Gdx.graphics.getWidth() / 2) // Left side of the screen
    {
        p.getVel().x = -wh.playerSpeed;
    }

    return false;
}

Thanks for any help! :)

1
If I was you, I would be using "p.getPosition().y += playerSpeed*Gdx.graphics.getDeltaTime();" because it updates your position according to your rendering frames per second. It removes jumpyness and laggyness. - Fish
Thanks that helps! :) - Adam Brodin

1 Answers

0
votes

I fixed it well i fixed it in a kind of cheaty way i guess. Instead of doing: if(screenX >= Gdx.graphics.getWidth() / 2) // Right side of the screen { p.getVel().x = wh.playerSpeed; }

if(screenX <= Gdx.graphics.getWidth() / 2) // Left side of the screen
{
    p.getVel().x = -wh.playerSpeed;
}

I did this: if(screenX >= Gdx.graphics.getWidth() / 2) // Right side of the screen { p.getVel().x = 12; }

    if(screenX <= Gdx.graphics.getWidth() / 2) // Left side of the screen
    {
        p.getVel().x = -12;
    }

And also the y movement i fixed it to a more smoother movement style thanks to Fish, here's the code: p.getPosition().y += playerSpeed * Gdx.graphics.getDeltaTime();

That's all for me! :)