示例#1
0
        protected override void DoAddCollider(Body body, float mass)
        {
            CheckDropAxis();
            Vector2 sz = VectorConverter.Convert(size * transform.lossyScale, to2dMode);

            connectedBody = body;
            Physics.AddBox(body, isTrigger, sz.x, sz.y, VectorConverter.Convert(center * transform.lossyScale, to2dMode), mass);
        }
示例#2
0
        public void WeWillNotHitAColliderIfTheRayStartsInsideIt()
        {
            Assert.Inconclusive("This test is suspended as we need an active collider on the body to test on");
            Body body = Physics.AddBody();

            Physics.AddBox(body, false, 10, 10, new Vector2(0, 0), 1);
            bool hit = Physics.Raycast(Vector2.zero, Vector2.up, 100, 0);

            Assert.That(hit, Is.False);
        }
示例#3
0
        public void WeCanMissAllCollidersUsing3d()
        {
            Assert.Inconclusive("This test is suspended as we need an active collider on the body to test on");
            Body body = Physics.AddBody();

            Physics.AddBox(body, false, 10, 10, new Vector2(0, 50), 1);
            bool hit = Physics.Raycast(Vector2.zero, Vector2.right, 100, 0);

            Assert.That(hit, Is.False);
        }
示例#4
0
        public void WeCanDetermineAColliderHitUsing3d()
        {
            Assert.Inconclusive("This test is suspended as we need an active collider on the body to test on");
            Body body = Physics.AddBody();

            Physics.AddBox(body, false, 10, 10, new Vector2(0, 50), 1);
            bool hit = Physics.Raycast(Vector3.zero, -Vector3.forward, 100, 0);

            Assert.That(hit, Is.True);
        }
示例#5
0
        public void WeWillGetNoHitsIfThereIsNoFixturesAtThePoint()
        {
            Assert.Inconclusive("This test is suspended as we need an active collider on the body to test on");
            Body body = Physics.AddBody();

            Physics.AddBox(body, false, 10, 10, new Vector2(0, 50), 1);
            bool hit = Physics.Pointcast(new Vector2(-5, -5));

            Assert.That(hit, Is.False);
        }
示例#6
0
        public void WeWillGetAHitIfAFixtureIsThere()
        {
            Assert.Inconclusive("This test is suspended as we need an active collider on the body to test on");
            Body body = Physics.AddBody();

            Physics.AddBox(body, false, 10, 10, new Vector2(0, 50), 1);
            bool hit = Physics.Pointcast(new Vector2(5, 55));

            Assert.That(hit, Is.True);
        }
示例#7
0
        public void WeWillOnlyGetObjectsInDistance()
        {
            Assert.Inconclusive("This test is suspended as we need an active collider on the body to test on");
            Body body  = Physics.AddBody();
            Body body1 = Physics.AddBody();

            Physics.AddBox(body1, false, 10, 10, new Vector2(0, 50), 1);
            Physics.AddBox(body, false, 10, 10, new Vector2(0, 20), 1);
            RaycastHit[] hits = Physics.RaycastAll(Vector2.zero, Vector2.up, 30, 0);
            Assert.That(hits.Length, Is.EqualTo(1));
        }
示例#8
0
        public void WeWillGetInfOnTheClosestObjectHit()
        {
            Assert.Inconclusive("This test is suspended as we need an active collider on the body to test on");
            Body body  = Physics.AddBody();
            Body body1 = Physics.AddBody();

            Physics.AddBox(body, false, 10, 10, new Vector2(0, 20), 1);
            Physics.AddBox(body1, false, 10, 10, new Vector2(0, 50), 1);
            RaycastHit hit    = new RaycastHit();
            bool       hasHit = Physics.Raycast(Vector2.zero, Vector2.up, out hit, 100, 0);

            Assert.That(hasHit, Is.True);
            Assert.That(hit.body, Is.SameAs(body));
        }
示例#9
0
        public void WeCanGetHitInfoOnTheObjectThatWasHit()
        {
            Assert.Inconclusive("This test is suspended as we need an active collider on the body to test on");
            Body body = Physics.AddBody();

            Physics.AddBox(body, false, 10, 10, new Vector2(0, 50), 1);
            RaycastHit hit    = new RaycastHit();
            bool       hasHit = Physics.Raycast(Vector2.zero, Vector2.up, out hit, 100, 0);

            Assert.That(hasHit, Is.True);
            Assert.That(hit.body, Is.SameAs(body));
            Assert.That(hit.point, Is.EqualTo(new Vector3(0, 0, 45)));
            Assert.That(hit.normal, Is.EqualTo(new Vector3(0, 0, -1)));
            Assert.That(hit.distance, Is.EqualTo(45));
        }
示例#10
0
        protected override void DoAddCollider(Body body, float mass)
        {
            connectedBody = body;
            Vector2 cen = VectorConverter.Convert(center * transform.lossyScale, to2dMode);

            if (direction == 0 || height <= radius * 2)
            {
                float rad = radius * transform.lossyScale.z;
                Physics.AddCircle(body, isTrigger, rad, cen, mass);
            }
            else
            {
                if (direction == 1)
                {
                    Vector2 sz = new Vector2(height - radius * 2, radius * 2);

                    sz *= (Vector2)gameObject.transform.lossyScale;
                    Physics.AddBox(body, isTrigger, sz.x, sz.y, cen, mass);
                    sz /= 2;
                    float rad = sz.y;
                    sz.y = 0;
                    Physics.AddCircle(body, isTrigger, rad, cen + sz, mass);
                    Physics.AddCircle(body, isTrigger, rad, cen - sz, mass);
                }
                else
                {
                    Vector2 sz = new Vector2(radius * 2, height - radius * 2);
                    sz *= (Vector2)gameObject.transform.lossyScale;
                    Physics.AddBox(body, isTrigger, sz.x, sz.y, cen, mass);
                    sz /= 2;
                    float rad = sz.x;
                    sz.x = 0;
                    Physics.AddCircle(body, isTrigger, rad, cen + sz, mass);
                    Physics.AddCircle(body, isTrigger, rad, cen - sz, mass);
                }
            }
        }