public void ForceMoveInto(RaycastHit2D hit, float moveAmount, Dir4 dir)
        {
            float             collideDistance = moveAmount - hit.distance;
            PhysicsCollidable moveable        = hit.collider.GetComponent <PhysicsCollidable>();

            if (moveable)
            {
                PhysicsMove physicsMove = new PhysicsMove(hit, collideDistance, dir, movement);
                moveable.OnMoveInto(physicsMove);
            }
        }
예제 #2
0
        private bool CanMoveInto(RaycastHit2D hit, float distance, Dir4 dir)
        {
            PhysicsCollidable collidable = hit.collider.GetComponent <PhysicsCollidable>();

            if (collidable)
            {
                float collideDistance = distance - hit.distance;
                float allowedMove     = collidable.GetAllowedMoveInto(new PhysicsMove(hit, collideDistance, dir, movement));
                return(allowedMove == collideDistance);
            }
            else
            {
                float collideDistance = distance - hit.distance;
                float allowedMove     = 0;
                return(allowedMove == collideDistance);
            }
        }
        public float GetAllowedMoveInto(RaycastHit2D hit, float wantsToMove, Dir4 dir)
        {
            if (wantsToMove <= hit.distance && !TilemapHelpers.IsColliderTilemap(hit.collider))
            {
                return(wantsToMove);
            }
            float             allowedCollideDistance = 0;
            PhysicsCollidable moveable = hit.collider.GetComponent <PhysicsCollidable>();

            if (moveable)
            {
                float       collideDistance = wantsToMove - hit.distance;
                PhysicsMove physicsMove     = new PhysicsMove(hit, collideDistance, dir, movement);
                allowedCollideDistance = moveable.GetAllowedMoveInto(physicsMove);
            }
            float allowedDistance = allowedCollideDistance + hit.distance;

            return(Mathf.Clamp(allowedDistance, 0, wantsToMove));
        }