예제 #1
0
    private void moveNode(RoleNode pNode)
    {
        //屏幕外的要隐藏.
        //pNode.SetVisible((IsInScene(pNode)));
        MoveData aMoveData = pNode.moveData;

        if (aMoveData.MoveDelay > 0.0f)
        {
            aMoveData.MoveDelay -= Time.deltaTime;
            if (aMoveData.MoveDelay <= 0.0f)
            {
                pNode.MoveEndCallback();
            }
        }
        else if (pNode.IsMoving())
        {
            float dx = aMoveData.delaX * Time.deltaTime;
            float dz = aMoveData.delaY * Time.deltaTime;
            if (Mathf.Abs(dx) >= Mathf.Abs(aMoveData.dx))
            {
                dx           = aMoveData.dx;
                aMoveData.dx = 0.0f;
            }
            else
            {
                aMoveData.dx -= dx;
            }

            if (Mathf.Abs(dz) >= Mathf.Abs(aMoveData.dz))
            {
                dz           = aMoveData.dz;
                aMoveData.dz = 0.0f;
            }
            else
            {
                aMoveData.dz -= dz;
            }
            Vector3 curPos = pNode.GetPosition();
            curPos.x += dx;
            curPos.z += dz;
            pNode.SetPosition(curPos);

            if (aMoveData.dx == 0.0f && aMoveData.dz == 0.0f)
            {
                pNode.MoveEndCallback();
            }
        }
    }
예제 #2
0
    public void MoveTo(RoleNode MoveNode, Vector3 MoveTo)
    {
        Vector3 curPos = MoveNode.GetPosition();

        MoveTo.x = Mathf.Abs(MoveTo.x);
        MoveTo.z = Mathf.Abs(MoveTo.z);
        if (curPos.x != MoveTo.x || curPos.z != MoveTo.z)
        {
            Vector3 targetDir = MoveTo - curPos;//目标点的朝向 Vector3 tempDir=Vector3.Cross(transform.forward,targetDir.normalized);
            //float dotValue = Vector3.Dot(MoveNode.displayNode.transform.forward, targetDir.normalized);
            //float angle = Mathf.Acos(dotValue) * Mathf.Rad2Deg;//计算夹角
            //MoveNode.displayNode.transform.RotateAround(MoveNode.displayNode.transform.position, Vector3.up, angle);//旋转角色
            MoveNode.SetDir(targetDir);
            float su = MoveNode.moveData.SpeedUp > 4.0f ? 4.0f : MoveNode.moveData.SpeedUp;

            float duration = MoveNode.MoveTo(MoveTo.x, MoveTo.z, 1.0f);
            if (duration <= 0)
            {
                MoveNode.MoveEndCallback();
            }
        }
    }