public void AllowsNoDistanceIfDistanceToCollisionIs0()
        {
            var gameObject              = new GameObject("testObject");
            var physicsMovement         = gameObject.AddComponent <PhysicsMovement>();
            var collisionMoveController = CollisionMoveController.Create(gameObject.transform, physicsMovement);

            var collisionGameObject = new GameObject("collidedObject");
            var transform           = collisionGameObject.transform;
            var collider            = collisionGameObject.AddComponent <BoxCollider2D>();
            var collisionPoint      = new Vector2(1, 1);
            var collisionNormal     = Vector2.left;
            var rayDir = Dir4.right;
            var distanceToCollision = 0;
            var hit = RaycastHitHelpers.MockHit(collider, collisionPoint, collisionNormal, distanceToCollision);

            var distanceToCheck = 2f;
            var allowedDistace  = collisionMoveController.GetAllowedMoveInto(hit, distanceToCheck, rayDir);

            Assert.That(allowedDistace, Is.EqualTo(0));
        }
예제 #2
0
        public void ItReturnsSameHitOnNextGetUniqueCall()
        {
            var gameObject   = GameObjectHelpers.Create("factory");
            var omitCollider = gameObject.GetComponent <Collider2D>();
            var factory      = CollisionMoveHitsFactory.Create(omitCollider);

            var hitGameObject = GameObjectHelpers.CreateCollider("collider", Vector2.zero, Vector2.one);
            var collider      = hitGameObject.GetComponent <Collider2D>();
            var point         = Vector2.one;
            var normal        = Vector2.up;
            var distance      = 1;

            var hits = new RaycastHit2D[1] {
                RaycastHitHelpers.MockHit(collider, point, normal, distance)
            };
            var count            = 1;
            var firstCallResult  = factory.GetUnique(hits, count);
            var secondCallResult = factory.GetUnique(hits, count);

            Assert.That(firstCallResult[0].collider, Is.EqualTo(secondCallResult[0].collider));
        }
예제 #3
0
        public void ItFiltersHitsWithSameCollider()
        {
            var gameObject   = GameObjectHelpers.Create("factory");
            var omitCollider = gameObject.GetComponent <Collider2D>();
            var factory      = CollisionMoveHitsFactory.Create(omitCollider);

            var hitGameObject = GameObjectHelpers.CreateCollider("collider", Vector2.zero, Vector2.one);
            var collider      = hitGameObject.GetComponent <Collider2D>();
            var point         = Vector2.one;
            var normal        = Vector2.up;
            var distance      = 1;

            var hits = new RaycastHit2D[2] {
                RaycastHitHelpers.MockHit(collider, point, normal, distance),
                RaycastHitHelpers.MockHit(collider, point, normal, distance)
            };
            var count  = 2;
            var result = factory.GetUnique(hits, count);

            Assert.That(result.Count, Is.EqualTo(1));
        }
        public void AllowsFullDistanceIfCollidableAllows(float distanceToCollision)
        {
            var gameObject              = new GameObject("testObject");
            var physicsMovement         = gameObject.AddComponent <PhysicsMovement>();
            var collisionMoveController = CollisionMoveController.Create(gameObject.transform, physicsMovement);

            var collisionGameObject   = new GameObject("collidedObject");
            var transform             = collisionGameObject.transform;
            var collider              = collisionGameObject.AddComponent <BoxCollider2D>();
            var physicsMoveCollidable = collisionGameObject.AddComponent <PhysicsMoveCollidableMock>();

            physicsMoveCollidable.allowedMove = new Vector2(2, 0);
            var collisionPoint         = new Vector2(1, 1);
            var collisionNormal        = Vector2.left;
            var rayDir                 = Dir4.right;
            var rayDistanceToCollision = distanceToCollision;
            var hit = RaycastHitHelpers.MockHit(collider, collisionPoint, collisionNormal, rayDistanceToCollision);
            //var collisionMoveHit = new CollisionMoveHit(transform, collisionPoint, collisionNormal, rayDirection, rayDistanceToCollision);

            var distanceToCheck = 2f;
            var allowedDistace  = collisionMoveController.GetAllowedMoveInto(hit, distanceToCheck, rayDir);

            Assert.That(allowedDistace, Is.EqualTo(distanceToCheck));
        }