2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2020-01-15 12:07:09 +00:00
|
|
|
* @copyright 2020 Photon Storm Ltd.
|
2019-05-10 15:15:04 +00:00
|
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
2018-02-12 16:01:20 +00:00
|
|
|
*/
|
|
|
|
|
2017-06-22 15:22:21 +00:00
|
|
|
var Clamp = require('../../math/Clamp');
|
|
|
|
|
2018-02-09 16:04:43 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @function Phaser.Physics.Impact.GetVelocity
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-09-13 07:09:44 +00:00
|
|
|
* @param {number} delta - The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate.
|
2018-02-09 16:04:43 +00:00
|
|
|
* @param {number} vel - [description]
|
|
|
|
* @param {number} accel - [description]
|
|
|
|
* @param {number} friction - [description]
|
|
|
|
* @param {number} max - [description]
|
|
|
|
*
|
|
|
|
* @return {number} [description]
|
|
|
|
*/
|
2017-06-22 15:22:21 +00:00
|
|
|
var GetVelocity = function (delta, vel, accel, friction, max)
|
|
|
|
{
|
|
|
|
if (accel)
|
|
|
|
{
|
|
|
|
return Clamp(vel + accel * delta, -max, max);
|
|
|
|
}
|
|
|
|
else if (friction)
|
|
|
|
{
|
|
|
|
var frictionDelta = friction * delta;
|
|
|
|
|
|
|
|
if (vel - frictionDelta > 0)
|
|
|
|
{
|
|
|
|
return vel - frictionDelta;
|
|
|
|
}
|
|
|
|
else if (vel + frictionDelta < 0)
|
|
|
|
{
|
|
|
|
return vel + frictionDelta;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Clamp(vel, -max, max);
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = GetVelocity;
|