void SelfAndTargetRt_M()
    {
        if (Input.GetMouseButtonDown(1))
        {
            isRt = true;
        }
        if (Input.GetMouseButtonUp(1))
        {
            isRt = false;
        }
        if (Input.GetMouseButtonDown(0))
        {
            isLeftRt = true;
        }
        if (Input.GetMouseButtonUp(0))
        {
            isLeftRt = false;
        }
        if (isRt)
        {
            x += Input.GetAxis("Mouse X") * rotationSpeed;
            y -= Input.GetAxis("Mouse Y") * rotationSpeed;
            y = Mathf.Clamp(y, minAngleLimit, maxAngleLimit);
            transform.rotation = Quaternion.Euler(y, x, 0);
            player.transform.rotation = Quaternion.Euler(0, x, 0);
        }
        if (isLeftRt)
        {
            x += Input.GetAxis("Mouse X") * rotationSpeed;
            y -= Input.GetAxis("Mouse Y") * rotationSpeed;
            y = Mathf.Clamp(y, minAngleLimit, maxAngleLimit);
            transform.rotation = Quaternion.Euler(y, x, 0);
        }
        distancePos.y -= Input.GetAxis("Mouse ScrollWheel") * distanceSpeed;
        distancePos.y = Mathf.Clamp(distancePos.y, minTargetDis, maxTargetDis);
        transform.position = transform.rotation * new Vector3(0.0f, 0.0f, -distancePos.y) + player.position;
    }
老师;
上面脚本是挂载在 Camera上的 转向 和跟随人物的 实现部分!
下面部分是挂载到 人物身上的但是 想实现 按键盘上的 wsad 键的时候 人物的面向是正常了对应的wsad 但是前方向 不是对应 wsad 的方向 想让 前方向 对应 wsad 键方向 该怎么改动老师!
       #region
        float z = Input.GetAxis("Horizontal");
        float x = Input.GetAxis("Vertical");
        rigidbody.transform.position += new Vector3(z * speed * Time.deltaTime, 0, x * speed * Time.deltaTime);
        if (Mathf.Abs(z) > 0.05f || Mathf.Abs(x) > 0.05f)
        {
            isMove = true;
            rigidbody.transform.rotation = Quaternion.LookRotation(new Vector3(z, 0, x));
        }
        #endregion
首先是左右方向,使用camera的左右方向(cameraTrans通过自己的方式得到,这里指的是camera身上的transform组件)
cameraTrans.right
然后是前后方向,前后方向跟camera就不对应了
vector3 forward = Vector.ProjectOnPlane(cameraTrans.forward,Vector3.up);
rigidbody.transform.position +=(cameraTrans.right*z+forward*x)*Time.deltaTime
老师,我琢磨好久,还是有问题 刚开始 走动几次 按键时 方向都是默认面向 最开始的方向 前后左右按键转动是正常的 但是 在转动视角后 还是面向的最开始的前后 左右 不是当前视角的前后左右
 最开始的视角
最开始的视角
 最开始视角按键转动正常 camera  无旋转
最开始视角按键转动正常 camera  无旋转
 摄像机转动后人物还是不能让前方向对应 当前视角的 wsad上  该怎么改动呢 折腾一天写不出来 对旋转太模糊,更加迷糊了
 摄像机转动后人物还是不能让前方向对应 当前视角的 wsad上  该怎么改动呢 折腾一天写不出来 对旋转太模糊,更加迷糊了 
 float z = Input.GetAxis("Horizontal");
        float x = Input.GetAxis("Vertical");
        Vector3 forward = Vector3.ProjectOnPlane(camera.forward, Vector3.up);
        rigidbody.transform.position += (camera.right * z + forward * x) * Time.deltaTime * speed;
        if (Mathf.Abs(z) > 0.05f || Mathf.Abs(x) > 0.05f)
        {
            transform.rotation = Quaternion.LookRotation(new Vector3(z, 0, -x));
            PlayerState = PlayerStatus.KeyMove;
        }
        else
        {
            PlayerState = PlayerStatus.Idle;
        }
错误处就是 他一直是面向的 最开始游戏的视角的前后左右方向
在该怎么改动呢 不会了