예제 #1
0
    public virtual void Init(ProjectileComponent projector, Vector2 relativePosition, float relativeDirection)
    {
        owner = projector.owner;
        MovementComponent ownerMovement = owner.GetComponent <MovementComponent>();
        MovementComponent movement      = GetComponent <MovementComponent>();

        target = owner.target;

        switch (projector.targetType)
        {
        case ProjectileComponent.TargetType.LOCATION:
        {
            movement.Direction = VEasyCalculator.GetDirection(owner.transform.position, projector.targetPosition) + relativeDirection;
        }
        break;

        case ProjectileComponent.TargetType.UNIT:
        {
        }
        break;

        case ProjectileComponent.TargetType.NONE:
        {
            movement.Direction = ownerMovement.Direction + relativeDirection;
        }
        break;
        }

        gameObject.transform.position = owner.transform.position + new Vector3(relativePosition.x, relativePosition.y, 0);
    }
예제 #2
0
    public static Vector2 GetRotatedPosition(float degrees, Vector2 pos)
    {
        float prevDegrees = VEasyCalculator.GetDirection(new Vector2(0f, 0f), pos);

        float distance = Vector2.Distance(new Vector2(0f, 0f), pos);

        return(GetRotatedPosition(prevDegrees + degrees, distance));
    }
예제 #3
0
    // TODO: 겹쳐있는 동안, 겹친 정도에 따라, 겹치지 않는 방향으로 아주 약간씩 이동시키는 로직 추가
    // 그 로직을 Bounce Action - Block 에서 사용하도록 할 것임
    // 아니 그냥 거기에 구현하는게 맞나?

    public override void Init()
    {
        if (initRotateToTarget == true)
        {
            if (owner.target != null)
            {
                Direction = VEasyCalculator.GetDirection(owner, owner.target);
            }
        }
    }
 private void RotateToCursor()
 {
     if (rotateToCursor == true)
     {
         Vector2 playerPosition     = new Vector2(transform.position.x, transform.position.y);
         Vector2 mouseWorldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         transform.eulerAngles = new Vector3(0, 0,
                                             VEasyCalculator.GetDirection(playerPosition, mouseWorldPosition) + SpriteManager.spriteDefaultRotation);
     }
 }
예제 #5
0
    protected override IEnumerator PatternFramework()
    {
        isPatternRunning = true;

        for (int i = 0; i < count; ++i)
        {
            if (blockBulletFire == false)
            {
                direction = VEasyCalculator.GetDirection(position, target.transform.position);

                Bullet bulletInstance = Instantiate(bulletPrefab);

                bulletInstance.transform.position = position;

                MovementComponent move = bulletInstance.GetComponent <MovementComponent>();

                if (move == null)
                {
                    Destroy(bulletInstance);
                }

                switch (type)
                {
                case TraceType.STATIC:
                {
                    move.Direction = direction;
                }
                break;
                }

                if (delay > 0f)
                {
                    yield return(new WaitForSeconds(delay));
                }
            }
        }

        blockBulletFire  = false;
        isPatternRunning = false;
    }
예제 #6
0
    private void MovementProcess(MovementType _movementType)
    {
        Speed = originSpeed;

        foreach (float speedModulateFactor in speedModulateDic.Values)
        {
            Speed = Speed * speedModulateFactor;
        }

        switch (_movementType)
        {
        case MovementType.STRAIGHT:
        {
            float moveDis = speed * Time.fixedDeltaTime;

            Vector2 moveVector = VEasyCalculator.GetRotatedPosition(direction, moveDis);

            Vector2 v2Pos = owner.transform.position;
            owner.transform.position = v2Pos + moveVector;
        }
        break;

        case MovementType.TURN_LERP:
        {
            if (owner.target == null)
            {
                MovementProcess(MovementType.STRAIGHT);

                speedModulateDic[SpeedModulateType.BY_TARGET_LOST] = targetLostSpeed;
                return;
            }

            speedModulateDic[SpeedModulateType.BY_TARGET_LOST] = 1f;

            float moveDis = speed * Time.fixedDeltaTime;

            float dirToTarget = VEasyCalculator.GetDirection(owner, owner.target);

            float deltaDir = VEasyCalculator.GetLerpDirection(
                direction, dirToTarget, turnFactor * Time.fixedDeltaTime) - direction;

            if (Mathf.Abs(deltaDir) < minTurnFactor * Time.fixedDeltaTime)
            {
                Direction += Mathf.Sign(deltaDir) * minTurnFactor * Time.fixedDeltaTime;
            }
            else
            {
                Direction += deltaDir;
            }

            Vector2 moveVector = VEasyCalculator.GetRotatedPosition(direction, moveDis);

            Vector2 v2Pos = owner.transform.position;
            owner.transform.position = v2Pos + moveVector;
        }
        break;

        case MovementType.TURN_LERP_BY_DISTANCE:
        {
            if (owner.target == null)
            {
                MovementProcess(MovementType.STRAIGHT);

                speedModulateDic[SpeedModulateType.BY_TARGET_LOST] = targetLostSpeed;
                return;
            }

            speedModulateDic[SpeedModulateType.BY_TARGET_LOST] = 1f;

            float moveDis = speed * Time.fixedDeltaTime;

            float dirToPlayer = VEasyCalculator.GetDirection(owner, owner.target);

            float disToPlayer = VEasyCalculator.GetDistance(owner.target, owner);

            float deltaDir = VEasyCalculator.GetLerpDirection(
                direction, dirToPlayer, turnFactor * Time.fixedDeltaTime,
                maxTurnByDis, minTurnByDis, disToPlayer, disFactor * Time.fixedDeltaTime) - direction;

            if (Mathf.Abs(deltaDir) < minTurnFactor * Time.fixedDeltaTime)
            {
                Direction += Mathf.Sign(deltaDir) * minTurnFactor * Time.fixedDeltaTime;
            }
            else
            {
                Direction += deltaDir;
            }

            Vector2 moveVector = VEasyCalculator.GetRotatedPosition(direction, moveDis);

            Vector2 v2Pos = owner.transform.position;
            owner.transform.position = v2Pos + moveVector;
        }
        break;

        case MovementType.TURN_REGULAR:
        {
            if (owner.target == null)
            {
                MovementProcess(MovementType.STRAIGHT);

                speedModulateDic[SpeedModulateType.BY_TARGET_LOST] = targetLostSpeed;
                return;
            }

            speedModulateDic[SpeedModulateType.BY_TARGET_LOST] = 1f;

            float moveDis = speed * Time.fixedDeltaTime;

            float dirToTarget = VEasyCalculator.GetDirection(owner, owner.target);

            Direction = VEasyCalculator.GetTurningDirection(
                direction, dirToTarget, turnFactor * Time.fixedDeltaTime);

            Vector2 moveVector = VEasyCalculator.GetRotatedPosition(direction, moveDis);

            Vector2 v2Pos = owner.transform.position;
            owner.transform.position = v2Pos + moveVector;
        }
        break;

        case MovementType.TURN_REGULAR_DISTANCE:
        {
            if (owner.target == null)
            {
                MovementProcess(MovementType.STRAIGHT);

                speedModulateDic[SpeedModulateType.BY_TARGET_LOST] = targetLostSpeed;
                return;
            }

            speedModulateDic[SpeedModulateType.BY_TARGET_LOST] = 1f;

            float moveDis = speed * Time.fixedDeltaTime;

            float dirToPlayer = VEasyCalculator.GetDirection(owner, owner.target);

            float disToPlayer = VEasyCalculator.GetDistance(owner.target, owner);

            Direction = VEasyCalculator.GetTurningDirection(
                direction, dirToPlayer, turnFactor * Time.fixedDeltaTime,
                maxTurnByDis, minTurnByDis, disToPlayer, disFactor * Time.fixedDeltaTime);

            Vector2 moveVector = VEasyCalculator.GetRotatedPosition(direction, moveDis);

            Vector2 v2Pos = owner.transform.position;
            owner.transform.position = v2Pos + moveVector;
        }
        break;

        case MovementType.VECTOR:
        {
            int dirCount = 0;

            for (int d = 0; d < 4; ++d)
            {
                if (moveDir[d] == true)
                {
                    dirCount++;
                }
            }

            float moveDis = speed * Time.fixedDeltaTime;

            float reduceByMultiDirection = 0.7071f;         // 1/root(2)
            if (dirCount >= 2)
            {
                moveDis = speed * Time.deltaTime * reduceByMultiDirection;
            }

            Vector2 delta = new Vector2(0f, 0f);
            if (moveDir[(int)WorldGeneral.Direction.LEFT] == true)
            {
                delta.x -= moveDis;
            }
            else if (moveDir[(int)WorldGeneral.Direction.RIGHT] == true)
            {
                delta.x += moveDis;
            }
            if (moveDir[(int)WorldGeneral.Direction.UP] == true)
            {
                delta.y += moveDis;
            }
            else if (moveDir[(int)WorldGeneral.Direction.DOWN] == true)
            {
                delta.y -= moveDis;
            }

            Vector2 v2Pos = owner.transform.position;
            owner.transform.position = v2Pos + delta;
        }
        break;
        }
    }
예제 #7
0
    private void BounceProcess(HitResult hr, BounceProcessType _type)
    {
        Unit owner = GetComponent <Unit>();

        MovementComponent ownerMovable = hr.owner.GetComponent <MovementComponent>();

        if (ownerMovable == null)
        {
            return;
        }

        switch (_type)
        {
        case BounceProcessType.REFLECT:
        {
            Wall hitWall = hr.target as Wall;
            if (hitWall == null)
            {
                return;
            }

            if (hitWall.direction == WorldGeneral.Direction.DOWN)
            {
                if (ownerMovable.Direction >= 90f &&
                    ownerMovable.Direction < 270f)
                {
                    ownerMovable.Direction = 180f - ownerMovable.Direction;
                }
            }
            else if (hitWall.direction == WorldGeneral.Direction.LEFT)
            {
                if (ownerMovable.Direction < 180f)
                {
                    ownerMovable.Direction = 360f - ownerMovable.Direction;
                }
            }
            else if (hitWall.direction == WorldGeneral.Direction.RIGHT)
            {
                if (ownerMovable.Direction >= 180f)
                {
                    ownerMovable.Direction = 360f - ownerMovable.Direction;
                }
            }
            else if (hitWall.direction == WorldGeneral.Direction.UP)
            {
                if (ownerMovable.Direction < 90f ||
                    ownerMovable.Direction >= 270f)
                {
                    ownerMovable.Direction = 180f - ownerMovable.Direction;
                }
            }
        }
        break;

        case BounceProcessType.DESTROY:
        {
            Wall hitWall = hr.target as Wall;
            if (hitWall == null)
            {
                return;
            }

            StartCoroutine(DelayedDestroy(destroyDelay));
        }
        break;

        case BounceProcessType.REVERSE:
        {
            ownerMovable.Direction += 180f;
        }
        break;

        case BounceProcessType.TO_TARGET:
        {
            if (owner.target == null)
            {
                BounceProcess(hr, BounceProcessType.REVERSE);
                return;
            }

            float dirToTarget = VEasyCalculator.GetDirection(ownerMovable.owner, ownerMovable.owner.target);
            ownerMovable.Direction = dirToTarget;
        }
        break;

        case BounceProcessType.TO_TARGET_REVERSE:
        {
            if (owner.target == null)
            {
                BounceProcess(hr, BounceProcessType.REVERSE);
                return;
            }

            float dirToTarget = VEasyCalculator.GetDirection(ownerMovable.owner, ownerMovable.owner.target);
            ownerMovable.Direction = dirToTarget + 180f;
        }
        break;

        case BounceProcessType.BLOCK:
        {
            // TODO: position 만 충돌 반대 방향으로 밈
        }
        break;
        }
    }