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.
Answer
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;
No comments:
Post a Comment