Pivot vs Rotation

For some strange reason my x rotation was spinning around the balls instead of staying in place and pivoting.

I checked out the code on Github but I’m trying to figure out what went wrong for learning purposes.

The CameraRotation script was correct and I’m sure I attached it to the Person parent object.

Is there a setting I accidentally toggled?

Any chance of a video of the behaviour?

Wish I did.

Since I also overrode my working directory, I unfortunately don’t have the code either. (lesson learned)

But in essence: I would press the arrow keys to spawn the balls and then when I would move my mouse left and right expecting to stand still and pivot left and right, it instead circled around the balls while facing it.

Fell like an orbit camera but not as precise.

@sampattuzzi

I was able to reproduce the error. I confirmed my code matches yours and the CameraRotation script is on Player.

Here is a copy of my CameraRotation script.

using UnityEngine;
using System.Collections;

public class CameraRotation : MonoBehaviour {

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
    float rotationSpeed = 5.0f;
    float mouseX = Input.GetAxis("Mouse X") * rotationSpeed;
    float mouseY = Input.GetAxis("Mouse Y") * rotationSpeed;
    transform.localRotation = Quaternion.Euler(0, mouseX, 0) * transform.localRotation;
    Camera camera = GetComponentInChildren<Camera>();
    camera.transform.localRotation = Quaternion.Euler(-mouseY, 0, 0) * camera.transform.localRotation;
    }
}

Here is what it looks like.

Sounds like it’s a problem in the parenting and tranforms of your player. Check that the camera isn’t offset relative to the parent that is being positioned.

2 Likes

Update Brain cells kicked in. Thank you for pointing me in the right direction! All fixed. I simply created an empty game object but didn’t move it to the same position as the camera before moving the camera underneath it.

Easy fix once I knew what to look for. Thanks again!

I’m having the same issue. Maybe a silly question but how would you check this?

Privacy & Terms