Example #1
0
 protected override void StateUpdate()
 {
     if (BehaviorState.Moving == state)
     {
         transform.position += Vector2ex.To3(Direction());
     }
 }
    protected override void StateUpdate()
    {
        if (BehaviorState.Attack == state)
        {
            if (PlayerTracking())
            {
                GameObject player  = GameObject.FindWithTag("Player");
                Vector2    destDir = (Vector2ex.By3(player.transform.position) - Vector2ex.By3(transform.position)).normalized;

                float angle = Vector2.Angle(destDir, direction);
                if (angle <= weaponRotateSpeed * Time.deltaTime)
                {
                    destDir = direction;
                    weapon.WeaponFire();
                }
                else
                {
                    bool isRevClockwise = direction.x * destDir.y - direction.y * destDir.x >= 0;
                    direction = Vector2ex.Rotate(direction, weaponRotateSpeed * Mathf.Deg2Rad * Time.deltaTime * (isRevClockwise ? 1 : -1));
                }
            }
            else
            {
                SetStateIdle();
            }
        }
        else if (BehaviorState.Moving == state)
        {
            transform.position += Vector2ex.To3(direction);
        }
    }
Example #3
0
    protected override void StateUpdate()
    {
        if (BehaviorState.Bike_riding == state)
        {
            if (PlayerTracking())
            {
                if (Vector2.Distance(Vector2ex.By3(GameObject.FindWithTag("Player").transform.position), Vector2ex.By3(transform.position)) < 100)
                {
                    SetState_BikeOut();
                    animator.SetTrigger("isBikeFinish");
                }
            }



            //으아 길찾기
            if (TimeEx.Cooldown(ref astar_cooldown) == 0)
            {
                astar_cooldown = 0.5f;
                if ((astar_lastSucceeded = astarPathFinder.경로검색(GameObject.FindWithTag("Player").transform.position)) == true)
                {
                    List <Astar.최단경로노드> path = astarPathFinder.GetPath();
                    astar_index      = 0;
                    astar_dir        = Vector2ex.By3(path[0].월드위치) - Vector2ex.By3(transform.position);
                    astar_remainDist = astar_dir.magnitude;
                    astar_dir       /= astar_remainDist;
                }
            }
            if (astar_lastSucceeded)
            {
                float movement = bikeSpeed * Time.deltaTime;
                while (true)
                {
                    if (astar_remainDist < movement)
                    {
                        transform.position += Vector2ex.To3(astar_dir) * astar_remainDist;
                        movement           -= astar_remainDist;


                        List <Astar.최단경로노드> path = astarPathFinder.GetPath();
                        astar_index++;
                        if (astar_index >= path.Count)
                        {
                            astar_cooldown = 0;
                            break;
                        }
                        astar_dir        = Vector2ex.By3(path[astar_index].월드위치) - Vector2ex.By3(transform.position);
                        astar_remainDist = astar_dir.magnitude;
                        astar_dir       /= astar_remainDist;
                    }
                    else
                    {
                        transform.position += Vector2ex.To3(astar_dir) * movement;
                        astar_remainDist   -= movement;
                        break;
                    }
                }
            }

            lrFliper.In(astar_dir);
        }
        else if (BehaviorState.Bike_out == state)
        {
            float movement = bikeSpeed * Time.deltaTime;
            transform.position += Vector2ex.To3(astar_dir) * movement;
        }
        else if (BehaviorState.Attack_machinegun == state ||
                 BehaviorState.Attack_machinegun_prefire == state ||
                 BehaviorState.Attack_grenadelauncher == state)
        {
            if (PlayerTracking())
            {
                GameObject player  = GameObject.FindWithTag("Player");
                Vector2    destDir = (Vector2ex.By3(player.transform.position) - Vector2ex.By3(transform.position)).normalized;

                float angle = Vector2.Angle(destDir, direction);
                if (angle <= weaponRotateSpeed * Time.deltaTime)
                {
                    if (state == BehaviorState.Attack_grenadelauncher)
                    {
                        weapon_GrenadeLauncher.WeaponFire();
                    }
                    else
                    {
                        weapon_MG.WeaponFire();
                    }
                    direction = destDir;
                }
                else
                {
                    bool isRevClockwise = direction.x * destDir.y - direction.y * destDir.x >= 0;
                    direction = Vector2ex.Rotate(direction, weaponRotateSpeed * Mathf.Deg2Rad * Time.deltaTime * (isRevClockwise ? 1 : -1));
                }
            }
            else
            {
                if (BehaviorState.Attack_machinegun == state)
                {
                    stateTime -= 1;
                    if (stateTime <= 0)
                    {
                        SetState_Idle();
                    }
                    else
                    {
                        SetState_AttackMachinegun_Prefire();
                    }
                }
            }
        }
        else if (BehaviorState.Moving == state)
        {
            transform.position += Vector2ex.To3(direction);
        }
    }
Example #4
0
 protected virtual void Update()
 {
     transform.position += Vector2ex.To3(velocity * Time.deltaTime * direction);
 }