Ejemplo n.º 1
0
        protected internal MinimumTranslationVector intersects(Collider2 other)
        {
            var shape1 = this.shape;
            var shape2 = other.shape;

            return(shape1.intersects(shape2));
        }
Ejemplo n.º 2
0
        private void init()
        {
            if (_material == null)
            {
                _material = Root.instance.resources.findMaterial("basewhite");
            }

            _transform = gameObject.transform2();
            _collider  = gameObject.collider();

            if (_collider != null)
            {
                _collider.hasRigidbody = true;
            }
        }
Ejemplo n.º 3
0
        public static MinimumTranslationVector getCollision(ICollidable shape, List <Collider2> triggers, out Collider2 hit)
        {
            hit = null;

            var results = Root.instance.physicsQuadTree2.Query(shape.bounds);

            if (results.Count > 0)
            {
                var overlap  = double.MaxValue;
                var smallest = Axis.Zero;
                foreach (var r in results.Where(x => !x.hasRigidbody))
                {
                    var mtv = shape.intersects(r.shape);
                    if (mtv.intersects && r.isTrigger)
                    {
                        if (!triggers.Contains(r))
                        {
                            triggers.Add(r);
                        }
                    }
                    else if (mtv.intersects && mtv.overlap < overlap)
                    {
                        overlap  = mtv.overlap;
                        smallest = mtv.smallest;
                        hit      = r;
                    }
                }

                if (hit != null)
                {
                    return(new MinimumTranslationVector(smallest, overlap));
                }
            }

            return(MinimumTranslationVector.Zero);
        }