BlessHayGaming
5/11/2018 - 5:24 AM

Numeric Springing

/// @numeric_springing(value, velocity, target_value, damping_ratio, angular_frequency, time_step);
/// @desc	Numeric springing function.
/// @arg	value
/// @arg	velocity
/// @arg	target_value
/// @arg	damping_ratio
/// @arg	angular_frequency
/// @arg	time_step

var _ret,                               //Array containing output value and velocity
_left = argument0,                      //Input value
_v = argument1*(room_speed/argument5),  //Input velocity
_left_t = argument2,                    //Target value
_damping = argument3,                   //Damping of the oscillation (0 = no damping, 1 = critically damped)
_ang_freq = 2*pi*argument4,             //Oscillations per second
_t = argument5/room_speed,              //How much of a second each step/use of the script takes (1 = normal time, 2 = twice as fast,..)
_delta_v, _delta_left, _delta;

_delta = (1+2*_t*_damping*_ang_freq)+power(_t,2)*power(_ang_freq,2);
_delta_left = (1+2*_t*_damping*_ang_freq)*_left+_t*_v+power(_t,2)*power(_ang_freq,2)*_left_t;
_delta_v = _v+_t*power(_ang_freq,2)*(_left_t-_left);

_ret[1] = (_delta_v/_delta)/(room_speed/argument5); //Output velocity
_ret[0] = _delta_left/_delta;                       //Output value

return _ret;