Search code examples
physicsphysics-engine

Most effective way to handle velocity


Basically, I am curious if xVel and yVel variables would work the best, or if I should use a velocity and a direction variable.

Also, this is how it would be handled on update: (psuedocode) For xVel and yVel :

x += xVel;
y += yVel;

For velocity and direction :

x += velocity * (cos(direction));
y += velocity * (sin(direction));

Note: I am not sure if the second one will work properly. I do not have trigonometry skills.

So, is the first way more effective, or the second? And am I doing the second one completely wrong?


Solution

  • It depends on your application. You can use an arctangent function to find the theta from any given moment, of course. However, if your have graphics which will rotate with the angle of the object, then you may want to stick to polar.

    Basically, the rule of thumb I use is this: If you're dealing with X and Y accelerations as well as velocities, then you want to stick to rectangular coordinates and use delta-x and delta-y variables. If you want to handle object rotation, and the angle is computed upon regularly, then you may want to use polar.

    It depends on the application.