Friday, October 11, 2019

mathematics - Create acceleration with direction


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

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...