I am trying to get my player to move based off acceleration and velocity. Here is how the velocity is found and the player is moved:
vel.x += acceleration.x;
coordinates.x += vel.x;
The coordinates
controls where the player is. Here is how acceleration is calculated:
if(moveRight && !(acceleration.x >= .1f)){
acceleration.x += .1f * Gdx.graphics.getDeltaTime();
}
First question: Is this a good way to move the player if I am going to use mass and force to move the player.
I am also trying to get the player to come to a halt based off the acceleration, here is the extended version of the above code where I try to do this:
if(moveRight && !(acceleration.x >= .1f)){
acceleration.x += .1f * Gdx.graphics.getDeltaTime();
}else if(!moveRight && (vel.x > 0)){
acceleration.x -= .1f * Gdx.graphics.getDeltaTime();
}
However, this doesn't work. When I move forward it accelerates forward, then when I let go, it stops, then shoots backwards.
Second question: How can I get the above code to work in the way I desired.
Thanks for any help regarding these few questions.