Nez.Portable/ECS/Components/Physics/Mover.cs
/// <summary>
/// moves the entity taking collisions into account
/// </summary>
/// <returns><c>true</c>, if move actor was newed, <c>false</c> otherwise.</returns>
/// <param name="motion">Motion.</param>
/// <param name="collisionResult">Collision result.</param>
moves the entity taking collisions into account
moves the entity taking collisions into account
public bool move(Vector2 motion, out CollisionResult collisionResult)
        {
            collisionResult = new CollisionResult();
            if (entity.getComponent<Collider>() == null || _triggerHelper == null)
            {
                entity.transform.position += motion;
                return false;
            }
            var colliders = entity.getComponents<Collider>();
            for (var i = 0; i < colliders.Count; i++)
            {
                var collider = colliders[i];
                if (collider.isTrigger)
                    continue;
                var bounds = collider.bounds;
                bounds.x += motion.X;
                bounds.y += motion.Y;
                var neighbors = Physics.boxcastBroadphaseExcludingSelf(
                    collider,
                    ref bounds,
                    collider.collidesWithLayers);
                foreach (var neighbor in neighbors)
                {
                    if (neighbor.isTrigger)
                        continue;
                    if (collider.collidesWith(neighbor, motion, out collisionResult))
                    {
                        motion -= collisionResult.minimumTranslationVector;
                    }
                }
            }
            ListPool<Collider>.free(colliders);
            entity.transform.position += motion;
            _triggerHelper.update();
            return collisionResult.collider != null;
        }
public bool move ( Vector2 motion , out CollisionResult collisionResult ) { collisionResult = new CollisionResult ( ) ; if ( entity . getComponent < Collider > ( ) == null || _triggerHelper == null ) { entity . transform . position += motion ; return false ; } var colliders = entity . getComponents < Collider > ( ) ; for ( var i = 0 ; i < colliders . Count ; i ++ ) { var collider = colliders [ i ] ; if ( collider . isTrigger ) continue ; var bounds = collider . bounds ; bounds . x += motion . X ; bounds . y += motion . Y ; var neighbors = Physics . boxcastBroadphaseExcludingSelf ( collider , ref bounds , collider . collidesWithLayers ) ; foreach ( var neighbor in neighbors ) { if ( neighbor . isTrigger ) continue ; if ( collider . collidesWith ( neighbor , motion , out collisionResult ) ) { motion -= collisionResult . minimumTranslationVector ; } } } ListPool < Collider > . free ( colliders ) ; entity . transform . position += motion ; _triggerHelper . update ( ) ; return collisionResult . collider != null ; }
moves the entity taking collisions into account
moves the entity taking collisions into account
// no collider? just move and forget about it // 1. move all non-trigger Colliders and get closest collision // skip triggers for now. we will revisit them after we move. // fetch anything that we might collide with at our new position // skip triggers for now. we will revisit them after we move. // hit. back off our motion // 2. move entity to its new position if we have a collision else move the full amount. motion is updated when a collision occurs // 3. do an overlap check of all Colliders that are triggers with all broadphase colliders, triggers or not. // Any overlaps result in trigger events.
None
motion
Vector2
None
CollisionResult
out
collisionResult
None