collidesWith() public method

checks to see if this Collider collides with collider. If it does, true will be returned and result will be populated with collision data
public collidesWith ( Collider collider, CollisionResult &result ) : bool
collider Collider Collider.
result CollisionResult Result.
return bool
Example #1
0
        void IUpdatable.update()
        {
            if (isImmovable)
            {
                velocity = Vector2.Zero;
                return;
            }

            if (shouldUseGravity)
            {
                velocity += Physics.gravity * Time.deltaTime;
            }

            entity.transform.position += velocity * Time.deltaTime;

            CollisionResult collisionResult;

            // fetch anything that we might collide with at our new position
            var neighbors = Physics.boxcastBroadphaseExcludingSelf(_collider, _collider.collidesWithLayers);

            foreach (var neighbor in neighbors)
            {
                // if the neighbor collider is of the same entity, ignore it
                if (neighbor.entity == entity)
                {
                    continue;
                }

                if (_collider.collidesWith(neighbor, out collisionResult))
                {
                    // if the neighbor has an ArcadeRigidbody we handle full collision response. If not, we calculate things based on the
                    // neighbor being immovable.
                    var neighborRigidbody = neighbor.entity.getComponent <ArcadeRigidbody>();
                    if (neighborRigidbody != null)
                    {
                        processOverlap(neighborRigidbody, ref collisionResult.minimumTranslationVector);
                        processCollision(neighborRigidbody, ref collisionResult.minimumTranslationVector);
                    }
                    else
                    {
                        // neighbor has no ArcadeRigidbody so we assume its immovable and only move ourself
                        entity.transform.position -= collisionResult.minimumTranslationVector;
                        var relativeVelocity = velocity;
                        calculateResponseVelocity(
                            ref relativeVelocity,
                            ref collisionResult.minimumTranslationVector,
                            out relativeVelocity);
                        velocity += relativeVelocity;
                    }
                }
            }
        }