accelerate(
var* speed,var accel,var friction);
Calculates the move distance for a given speed
and acceleration. The resistance of a surrounding medium can be given
by the friction parameter.
This function can be used for actor movement and rotation.
Parameters:
speed |
current speed in quants per tick. This value is changed by the acceleration.
|
accel |
acceleration in quants per square tick. |
friction |
the resistance parameter of the surrounding medium, in the range of 0..1. 0 means no resistance, 1 full resistance. |
Returns:
Distance to cover in quants.
Modifies:
speed - current speed vector in quants per tick.
Speed:
Fast
Algorithm:
if (friction == 0) {
distance = speed*time_step + 0.5*accel*time_step*time_step
speed = speed + accel*time_step
} else {
distance = accel*time_step/friction + (speed-accel/friction)*(1-exp(-friction*time_step))/friction
speed = accel/friction + (speed-accel/friction)*exp(-friction*time_step)
}
Example:
var aspeed; // local var to store the current angular speed
// accelerate the camera left-right rotation with cursor keys
vec_add(camera.pan,accelerate(aspeed,5*key_force.x,0.7));
See also:
vec_accelerate,
smooth
► latest
version online