gm-core/delta

Feature Request:

Closed this issue · 1 comments

I've been using this system so far for my game, I was hoping you could maybe add some functionality for me as I'm having a hard time figuring it out.

I've got this Delta Time based Lerp function I put together and it seems to work.

/// @desc Returns a value linearly interpolated towards a second value by a percentage /// @param val1 /// @param val2 /// @param amount function dlerp(argument0, argument1, argument2){ return lerp(argument1, argument0, power(2, -argument2 * global.__delta_stepFactor)); }

This issue is with spring motion, I've got this code in my game:
//Spring Scale Animation for Landing x_scale_spd = lerp(x_scale_spd, (1 - x_scale) * 0.5, 0.2); y_scale_spd = lerp(y_scale_spd, (1 - y_scale) * 0.5, 0.2);

and i've tried using the dlerp script or changing the 0.2 to d(0.2) and the results are still not consistent.
I've put together this script below and it still doesn't work, if you can help with this at all I'd appreciate it, thankyou!
`
/// @desc Returns an array with data for Frame Independent Spring Motion applied to the input
/// @param input
/// @param target
/// @param velocity
/// @param damping
/// @param frequency
function dspring(argument0, argument1, argument2, argument3, argument4){

var _dt =  global.__delta_stepFactor;
var _position = argument0;
var _target_position = argument1;
var _velocity = argument2; 
var _zeta = argument3;
var _omega = argument4;

var _xo = _position - _target_position
var _omegazeta = _omega * _zeta;
var _alpha = _omega * sqrt(1.0 - _zeta*_zeta);
var _exp = exp(-_dt * _omegazeta);
var _cos = cos(_dt * _alpha);
var _sin = sin(_dt * _alpha);
var _c2 = (_velocity + _xo*_omegazeta) / _alpha;

var _pos = _target_position + _exp*(_xo*_cos + _c2*_sin);
var _vel = -_exp*((_xo*_omegazeta - _c2*_alpha)*_cos + (_xo*_alpha + _c2*_omegazeta)*_sin);
return [_pos, _vel];

}
`

Found a different solution, fixed time step