Ejemplo n.º 1
0
    private void Spread()
    {
        //채석장을 향해 돌아서서
        //채석장이 어딨는데?
        int idx = GetWorkPosIdx();

        //만약에 타겟이 없으면 다시찾아
        if (idx == -1)
        {
            return;
        }

        //타겟을 정해준다
        target = WorkPositon_Manager.WP.quarryPosition[idx].gameObject.transform;

        //이렇게 하면 거리와 함께 방향도 알아낼 수 있지
        float   distance = 0.0f;
        Vector3 dir      = GetDir(target.position, transform.position, out distance);

        dir.y = 0;
        //해당 포인트랑 일정이상 가까워지면
        if (distance > amount)
        {
            transform.position += dir.normalized * moveSpeed * Time.deltaTime;
            //그쪽을 향해서 회전해
            transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(dir), rotSpeed * Time.deltaTime);
        }
        else if (distance <= amount)
        {
            //해당포인트의 차일드 갯수를 비교해서
            //포인트에 아무도 없다면
            if (target.childCount <= 0)
            {
                //채석장을 향해 회전하고싶다
                dirForQuarry = dir;
                //transform.forward = dirForQuarry.normalized;
                transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(-quarry.transform.forward), rotSpeed * Time.deltaTime);
                float angle = Vector3.SignedAngle(transform.forward, quarry.transform.position, Vector3.up);
                //채석장을 바라고보 섰다면 곡괭이질을 시작해
                if (angle < 15f)
                {
                    PositionsSelf pself = target.GetComponent <PositionsSelf>();
                    pself.atOnce = true;
                    transform.SetParent(target);
                    AnimChangeState(WorkMan.Quarrying);
                }
            }
            else if (target.childCount > 0)
            {
                state = WorkMan.Spread;
            }
        }
    }
Ejemplo n.º 2
0
    private void Move_To_Quarry(Vector3 x, Vector3 y)
    {
        //채석포인트에 일정이상 가까워지면
        float dist = Vector3.Distance(x, y);

        dirForQuarry       = x - y;
        dirForQuarry.y     = 0f;
        transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(dirForQuarry), rotSpeed * Time.deltaTime);
        if (dist >= graceDistance)
        {
            transform.position += dirForQuarry.normalized * moveSpeed * Time.deltaTime;
        }
        //흩어져
        else if (dist < graceDistance)
        {
            state = WorkMan.Spread;
        }
    }
Ejemplo n.º 3
0
    public void AnimChangeState(WorkMan wm)
    {
        state = wm;
        switch (wm)
        {
        case WorkMan.Idle:
            anim.SetFloat("Idle", valuePool[value]);
            break;

        case WorkMan.Move_To_Quarry:
            anim.SetTrigger("Let's Do this");
            break;

        case WorkMan.Quarrying:
            anim.SetTrigger("Quarrying");
            break;

        case WorkMan.PickUP:
            anim.SetTrigger("PickUP");
            break;

        case WorkMan.CarryingPayload:
            anim.SetTrigger("CarryingPayload");
            break;

        case WorkMan.PutDown:
            anim.SetTrigger("PutDown");
            break;

        case WorkMan.Success:
            anim.SetFloat("Success", successValuePool[successValue]);
            break;

        case WorkMan.Fail:
            anim.SetFloat("Defeat", valuePool[value]);
            break;
        }
    }