예제 #1
0
        public void CapsuleSphereCollision()
        {
            // r=1.5 at (0,8,0)
            var sphere = SphereBody.Create(_simulation,
                                           new Vector3(0, 8, 0),
                                           1.5f);

            // pointing straight up, should hit sphere
            var capsule1 = CapsuleBody.Create(this._simulation,
                                              new Vector3(0, 0, 0),
                                              Quaternion.Identity,
                                              1f,
                                              6f);

            // rotated 45deg, should miss sphere
            var capsule2 = CapsuleBody.Create(this._simulation,
                                              new Vector3(0, 0, 0),
                                              Quaternion.CreateFromAxisAngle(Vector3.UnitX, (float)(0.125 * Math.Tau)),
                                              1f,
                                              6f);

            // floating, rotated 90deg, should hit sphere
            var capsule3 = CapsuleBody.Create(this._simulation,
                                              new Vector3(8, 8, 0),
                                              Quaternion.CreateFromAxisAngle(Vector3.UnitZ, (float)(0.25 * Math.Tau)),
                                              1f,
                                              6f);

            Assert.IsTrue(PhysicsSimulation.CapsuleSphereCollision(capsule1, sphere));
            Assert.IsFalse(PhysicsSimulation.CapsuleSphereCollision(capsule2, sphere));
            Assert.IsTrue(PhysicsSimulation.CapsuleSphereCollision(capsule3, sphere));
        }
예제 #2
0
        public override void Initialize()
        {
            base.Initialize();

            spriteRenderer.Color = fadeColor;
            despawnAt            = Time.TotalTime + lifetime;

            body = Entity.AddComponent <CapsuleBody>();
            Entity.AddComponent(new BoxCollider(-8, -12, 8, 24)
            {
                Tag = Constants.Colliders.THING, IsTrigger = true
            });
            Entity.AddComponent(new BoxCollider(-40, -40, 80, 80)
            {
                Tag = Constants.Mechanics.TRIGGER_GRAVITY, IsTrigger = true
            });

            // use slow updates
            UpdateInterval = 10;
        }