# How do I derive an appropriate acceleration value for my game?

I am creating a Flappy Bird clone from this tutorial.

I have a question about acceleration in libgdx. The author assigned the bird a constant acceleration vector in the constructor of the bird

        acceleration = new Vector2(0, 460);


and later updated the velocity vector from the accleration vector with

        velocity.add(acceleration.cpy().scl(delta));


I understand generally why acceleration is constant - like the author mentioned, acceleration due to gravity is 9.81m/s^2, meaning that the speed of an object falling will increase by 9.81m/s every second. It seems the author somehow got from 9.81 real world value to 460 in the actual code. How does one go about deriving this value? Is this a standard derivation or something the author just made up?

• Perhaps every game unit is one inch, and that 460 value is meant to be in units of inches/second^2 (+20%). Commented Jan 25, 2015 at 3:42
• No i think the game would be in pixels. I might be wrong though Commented Jan 25, 2015 at 4:00
• You're probably correct. I was being cheeky; the units are arbitrary and can be whatever the game convention declares them to be. Commented Jan 25, 2015 at 4:12

How the author specifically got that value was via experimentation. From the comments:

Q: Hi James, you set acceleration.y to 460. How did you find this number? Is it static?

A: Acceleration was experimentally determined. Its value does not change.

And this is often the case when determining values for your game. You pick a value and play-test with it. Adjust the value according to your play-testing results.

Sometimes you can find something close to the value you want with some calculations. These calculations are similar to real world physics, but you'll need to take into account the game world. In this case the value likely has something to do with the number of pixels per unit of distance.

• The author was able to find the number of pixels width wise with Gdx.graphics.getWidth() and divided it by 136(game width), so i am assuming that amount is number of pixels per unit of distance. What would you do next with that to experiment? Commented Jan 25, 2015 at 3:58
• You'd choose what you want for the acceleration to be in those units. So, say your avatar is 100 pixels high and you'd say in real units you think the avatar is 1 foot high. Gravity is 32 feet per second squared. So, you'd have 320 pixels per second squared. Commented Jan 25, 2015 at 4:34
• What do you mean by avatar? Commented Jan 25, 2015 at 5:50
• Avatar is the main character. In your case, that would be the bird that's doing the flappin'. Commented Jan 25, 2015 at 6:10
• He defined the avatar as 17 game units width and 12 game units height. But the screen size varies though. How would you make that conversion between game units and ft so you can use the fact that gravity is 32 per second squared. Commented Jan 25, 2015 at 6:26

Adjust birdSpeed and pixelMovement in below code to achieve your 9.8m/s2 speed. s=0*t+1/2gt*t

Public Class bird extends Actor
{
private float pixelMovement=30;       // No of pixel you want to move bird in one touch
private float birdNextPosition;   //This will be used to hold next position of bird
private boolean birdisMoving=false; // flag to track bird movement
private float birdSpeed=80;
bird()
{
birdNextPosition=pixelMovement+getY();
}
@Override
public void act(float delta)
{
// set birdMoving flag true in stage class when you get any touch
if(birdisMoving() && getY()<= birdNextPosition)
{
setY(getY()+birdSpeed*delta);
}
if(getY()> birdNextPosition)
{
birdNextPosition=pixelMovement+getY();
setbirdisMoving(false);
}
}
@Override
public void draw(Batch batch, float parentAlpha)
{
batch.draw(birdTexture, getX(), getY());
}
}

• Where did you get 80 and 30 from? Commented Jan 28, 2015 at 19:21
• Those are random values, You have to adjust them accordingly, how smooth do you want to be your bird's movement. Commented Feb 2, 2015 at 8:52
• Like you didn't derive those values from 9/8? You said this code would "achieve your 9.8m/s2 speed" Commented Feb 2, 2015 at 9:00
• ok, birdspeed=32.3 and pixelMovement=49 will give you 9.8 m/s2. use s=0+1/2gt2 and v=0+gt to get above values. Commented Feb 2, 2015 at 18:01