Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to move my object with an acceleration in the proper direction. For example if I have these values:

friction = 0.3;
direction = 180;
speed = 5;

For making it clear, I need a formula to create a linear acceleration.

share|improve this question
up vote 5 down vote accepted

You can calculate the invidual components by using sin and cos:

xSpeed = sin(direction)*speed;
ySpeed = cos(direction)*speed;
xPos += xSpeed;
yPos += ySpeed;

Accleration is simply increasing the speed.

xAccel = sin(accelDirection)*accleration;
yAccel = cos(accelDirection)*accleration;
// [...]
xSpeed += xAccel;
ySpeed += yAccel;
share|improve this answer
Actually before posting this question I wrote this solution. Your answer will be completed by the Xavier Arias Botargues's answer. Thanks. – MahanGM Jul 22 '12 at 9:58

Acceleration is the rate at which velocity changes. If it is zero, then you will keep moving at your start velocity. If it is larger than zero, and in the same direction as the current velocity, velocity will increase.

velocity = old_velocity + acceleration;
position = old_position + velocity

If acceleration = 2, then your velocity will increase by 2 for each timestep.

share|improve this answer
This is similar to other 2 answers. Thanks. – MahanGM Jul 22 '12 at 10:01

To do any movement or physics calculations you should always use the time spent since the last frame (dt or delta); this depends on the main loop implementation, but is generaly passed to a method called update as parameter. (If this is not available assume dt = 1)

To update speed with acceleration and time and position with speed and time you can:

speed += acceleration * dt;
position += speed * dt;

Note that acceleration, speed and position are vectors, so they have the operations:

  • vector addition
  • scalar and vector multiplication

more info:

To create a vector with a given angle you can use the method described by Mr. Beast.

To simulate friction you can do something like:

speed -= speed * friction

Where friction should be a number: 0 < friction < 1

share|improve this answer
Yeah I didn't mention the time passing in my question. I'm using timeGetTime() to calculate previous frame. Thanks. – MahanGM Jul 22 '12 at 9:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.