• Create Account

### #ActualOlof Hedman

Posted 06 November 2012 - 12:33 PM

The general update mechanism of a 2D point with constant velocity towards a given aimed angle looks something like

float newX = x + cos(angle) * velocity * deltaTime;
float newY = y + sin(angle) * velocity * deltaTime;

The angle is expressed in radians, velocity is the speed of the projectiles, and deltaTime is the amount of time that has passed since the last update.

Though it makes sense to only recalculate the velocity-vector when the input change, since that should be a lot less often then the framerate.
Not that it likely matters much. (and maybe it's animated, and need to change every frame)
Another nitpick: "velocity" is always a vector, and speed is a scalar (the length of the velocity vector), so it would look neater if it said "speed" in the code

### #2Olof Hedman

Posted 06 November 2012 - 12:32 PM

The general update mechanism of a 2D point with constant velocity towards a given aimed angle looks something like

float newX = x + cos(angle) * velocity * deltaTime;
float newY = y + sin(angle) * velocity * deltaTime;

The angle is expressed in radians, velocity is the speed of the projectiles, and deltaTime is the amount of time that has passed since the last update.

Though it makes sense to only recalculate the velocity-vector when the input change, since that should be a lot less often then the framerate.
Not that it likely matters much. (and maybe it's animated)
Another nitpick: "velocity" is always a vector, and speed is a scalar (the length of the velocity vector), so it would look neater if it said "speed" in the code

### #1Olof Hedman

Posted 06 November 2012 - 12:31 PM

The general update mechanism of a 2D point with constant velocity towards a given aimed angle looks something like

float newX = x + cos(angle) * velocity * deltaTime;
float newY = y + sin(angle) * velocity * deltaTime;

The angle is expressed in radians, velocity is the speed of the projectiles, and deltaTime is the amount of time that has passed since the last update.

Though it makes sense to only recalculate the velocity-vector when the input change, since that should be a lot less often then the framerate.
Not that it likely matters much.
Another nitpick: "velocity" is always a vector, and speed is a scalar (the length of the velocity vector), so it would look neater if it said "speed" in the code

PARTNERS