Nez.Portable/ECS/Components/Physics/ArcadeRigidbody.cs
/// <summary>
/// given the relative velocity between the two objects and the MTV this method modifies the relativeVelocity to make it a collision
/// response.
/// </summary>
/// <param name="relativeVelocity">Relative velocity.</param>
/// <param name="minimumTranslationVector">Minimum translation vector.</param>
given the relative velocity between the two objects and the MTV this method modifies the relativeVelocity to make it a collision
response.
given the relative velocity between the two objects and the MTV this method modifies the relativeVelocity to make it a collision response .
void calculateResponseVelocity(
            ref Vector2 relativeVelocity,
            ref Vector2 minimumTranslationVector,
            out Vector2 responseVelocity)
        {
            var inverseMTV = minimumTranslationVector * -1f;
            Vector2 normal;
            Vector2.Normalize(ref inverseMTV, out normal);
            float n;
            Vector2.Dot(ref relativeVelocity, ref normal, out n);
            var normalVelocityComponent = normal * n;
            var tangentialVelocityComponent = relativeVelocity - normalVelocityComponent;
            if (n > 0.0f)
                normalVelocityComponent = Vector2.Zero;
            var coefficientOfFriction = _friction;
            if (tangentialVelocityComponent.LengthSquared() < _glue)
                coefficientOfFriction = 1.01f;
            responseVelocity = -(1.0f + _elasticity) * normalVelocityComponent
                               - coefficientOfFriction * tangentialVelocityComponent;
        }
void calculateResponseVelocity ( ref Vector2 relativeVelocity , ref Vector2 minimumTranslationVector , out Vector2 responseVelocity ) { var inverseMTV = minimumTranslationVector * - 1f ; Vector2 normal ; Vector2 . Normalize ( ref inverseMTV , out normal ) ; float n ; Vector2 . Dot ( ref relativeVelocity , ref normal , out n ) ; var normalVelocityComponent = normal * n ; var tangentialVelocityComponent = relativeVelocity - normalVelocityComponent ; if ( n > 0.0f ) normalVelocityComponent = Vector2 . Zero ; var coefficientOfFriction = _friction ; if ( tangentialVelocityComponent . LengthSquared ( ) < _glue ) coefficientOfFriction = 1.01f ; responseVelocity = - ( 1.0f + _elasticity ) * normalVelocityComponent - coefficientOfFriction * tangentialVelocityComponent ; }
given the relative velocity between the two objects and the MTV this method modifies the relativeVelocity to make it a collision
response.
given the relative velocity between the two objects and the MTV this method modifies the relativeVelocity to make it a collision response .
// first, we get the normalized MTV in the opposite direction: the surface normal // the velocity is decomposed along the normal of the collision and the plane of collision. // The elasticity will affect the response along the normal (normalVelocityComponent) and the friction will affect // the tangential component of the velocity (tangentialVelocityComponent) // if the squared magnitude of the tangential component is less than glue then we bump up the friction to the max // elasticity affects the normal component of the velocity and friction affects the tangential component
Vector2
out
relativeVelocity
None
minimumTranslationVector
Minimum translation vector.
Minimum translation vector .