Player Rotation

Options
Hey all,
I'm trying to implement a custom movement/rotation system using swipe gestures, and I'm running into issues. I started going off the PUN Asteroid example. I was able to implement my ship position to update up x units based on my Up/Down swipe but when I try to Left/Right swipe, it seems that my rotations are being overriden. I assume there's some networking logic that updates all ships that is doing something since my edits in Editor for rotation don't take either. Any ideas?
public bool Move(SwipeMovement.Movement muv)
        {
            Vector3 moving = Vector3.zero;
            if (muv == SwipeMovement.Movement.Down)
            {
                Debug.Log("Move Back");
                moving = Vector3.back;
                _animator.SetTrigger("MoveBack");
                StartCoroutine(GetComponent<SwipeMovement>().LerpMove(gameObject, transform.position, transform.position + (moving * 10), .167f));
            }
            else if (muv == SwipeMovement.Movement.Up)
            {
                Debug.Log("Move Forward");
                moving = Vector3.forward;
                _animator.SetTrigger("MoveForward");
                StartCoroutine(GetComponent<SwipeMovement>().LerpMove(gameObject, transform.position, transform.position + (moving * 10), .167f));
            }
            else if (muv == SwipeMovement.Movement.Left)
            {
                Debug.Log("Move Left");
                moving = Vector3.zero;
                StartCoroutine(GetComponent<SwipeMovement>().LerpRotate(gameObject, transform.rotation, transform.rotation * Quaternion.Euler(0, -90, 0), .167f));
                return true;
            }
            else if (muv == SwipeMovement.Movement.Right)
            {
                Debug.Log("Move Right");
                moving = Vector3.zero;
                //Quaternion rot = rigidbody.rotation * Quaternion.Euler(0, 90, 0);
                //rigidbody.MoveRotation(rot);
                transform.rotation *= Quaternion.Euler(0, 90f, 0);
                //_animator.SetTrigger("RotateRight");
                return true;
            }
            if (CheckOutOfBounds(moving))
            {
                Debug.Log("OOO");
                return false;
            }
            this.photonView.RPC("MoveShip", RpcTarget.Others, muv);
            return true;
        }

public IEnumerator LerpMove(GameObject go, Vector3 source, Vector3 target, float overTime)
        {
            float startTime = Time.time;
            while (Time.time < startTime + overTime)
            {
                go.transform.position = Vector3.Lerp(go.transform.position, target, (Time.time - startTime) / overTime * Time.deltaTime);
                yield return null;
            }
            go.transform.position = target;
        }

        public IEnumerator LerpRotate(GameObject go, Quaternion currentAngle, Quaternion targetAngle, float overTime)
        {
            float startTime = Time.time;
            Rigidbody rigidbody = go.GetComponent<Rigidbody>();
            while (Time.time < startTime + overTime)
            {
                //Quaternion rot = rigidbody.rotation * Quaternion.Euler(0, rotation * 90f * Time.fixedDeltaTime, 0);
                //rigidbody.MoveRotation(rot);
                transform.rotation = Quaternion.Slerp(currentAngle, targetAngle, (Time.time - startTime) / overTime * Time.deltaTime);
                //Quaternion deltaRotation = Quaternion.Euler(targetAngle * Time.deltaTime);
                //go.GetComponent<Rigidbody>().MoveRotation(go.GetComponent<Rigidbody>().rotation * deltaRotation);
                //transform.eulerAngles = currentAngle;
                yield return null;
            }
            transform.rotation = targetAngle;
        }

Comments

  • Wicked_Manatee
    edited May 2020
    Options
    The player has a PhotonView component tracking PhotonRigidbodyView component in itself, which has Sync Velocity and AngularVelocity checked PhotonTransformView in itself, which has Position and Rotation checked. The transform.position is tracked fine, but the transform.rotation is not. I've since removed the Move function from above and now only using the RPC for Targeting all via server for updates. I've tried using RotateTowards instead of Lerp/Slerp (and all those others commented out) without avail. I think the root of the problem is that I can't update the rotation, even in the Editor. It just resets to 0,0,0 and I don't understand where that's being restricted/overridden. The Rigidbody doesn't have rotation frozen on Y. Any ideas?