示例#1
0
    private void Tracer(Vector3 newPos)
    {
        Vector3 newDirection1st, newDirection2nd;

        // 자신의 위치에서 플레이어의 위치로 향하는 벡터.
        Vector3 diff = m_player.position - newPos;

        // X, Z의 절대값이 큰 쪽을 선택한다.
        if (Mathf.Abs(diff.x) > Mathf.Abs(diff.z))
        {
            newDirection1st = new Vector3(1, 0, 0) * Mathf.Sign(diff.x);
            newDirection2nd = new Vector3(0, 0, 1) * Mathf.Sign(diff.z);
        }
        else
        {
            newDirection2nd = new Vector3(1, 0, 0) * Mathf.Sign(diff.x);
            newDirection1st = new Vector3(0, 0, 1) * Mathf.Sign(diff.z);
        }

        // 두 후보 중 이동 가능한 방향을 선택한다.
        Vector3 newDir = DirectionChoice(newDirection1st, newDirection2nd);

        if (newDir == Vector3.zero)
        {
            m_grid_move.SetDirection(-m_grid_move.GetDirection());
        }
        else
        {
            m_grid_move.SetDirection(newDir);
        }
    }
示例#2
0
    private void Tracer(Vector3 newPos)
    {
        Vector3 newDirection1st, newDirection2nd;

        // 自分の位置からプレイヤーの位置に向かうベクトル.
        Vector3 diff = m_player.position - newPos;

        // X、Zの絶対値が大きい方を選ぶ.
        if (Mathf.Abs(diff.x) > Mathf.Abs(diff.z))
        {
            newDirection1st = new Vector3(1, 0, 0) * Mathf.Sign(diff.x);
            newDirection2nd = new Vector3(0, 0, 1) * Mathf.Sign(diff.z);
        }
        else
        {
            newDirection2nd = new Vector3(1, 0, 0) * Mathf.Sign(diff.x);
            newDirection1st = new Vector3(0, 0, 1) * Mathf.Sign(diff.z);
        }

        // 二つの候補から、移動可能な方向を選ぶ.
        Vector3 newDir = DirectionChoice(newDirection1st, newDirection2nd);

        if (newDir == Vector3.zero)
        {
            m_grid_move.SetDirection(-m_grid_move.GetDirection());
        }
        else
        {
            m_grid_move.SetDirection(newDir);
        }
    }
示例#3
0
    private void Tracer(Vector3 newPos)
    {
        Vector3 newDirection1st, newDirection2nd;

        // 从自身位置指向玩家位置的向量
        Vector3 diff = m_player.position - newPos;

        // 选择X,Z中绝对值更大的一个
        if (Mathf.Abs(diff.x) > Mathf.Abs(diff.z))
        {
            newDirection1st = new Vector3(1, 0, 0) * Mathf.Sign(diff.x);
            newDirection2nd = new Vector3(0, 0, 1) * Mathf.Sign(diff.z);
        }
        else
        {
            newDirection2nd = new Vector3(1, 0, 0) * Mathf.Sign(diff.x);
            newDirection1st = new Vector3(0, 0, 1) * Mathf.Sign(diff.z);
        }

        // 从两个候选值中选择可能移动的方向
        Vector3 newDir = DirectionChoice(newDirection1st, newDirection2nd);

        if (newDir == Vector3.zero)
        {
            m_grid_move.SetDirection(-m_grid_move.GetDirection());
        }
        else
        {
            m_grid_move.SetDirection(newDir);
        }
    }
    // Update is called once per frame
    public virtual void Update()
    {
        Quaternion targetRotation = Quaternion.LookRotation(m_move.GetDirection());
        float      t = 1.0f - Mathf.Pow(0.75f, Time.deltaTime * 30f);

        transform.localRotation = MathUtil.Slerp(transform.localRotation, targetRotation, t);
    }