Rotating around Y Axis?

Hi Everyone!

I have a little problem with my camera.
I have a round object in the middle of my scene (0,0,0).

My camera’s position is (0,0,5) and it aims at the round object.
The camera is inside a empty object that has the position (0,0,0).

My goal is to get the camera rotate around the objects (Y Axis) when I press the right and left arrow.

I’ve searched for about an hour now on the forums but can’t find anything useful :frowning:

I’m sure it is a very simple script so could anyone please help? :slight_smile:

  • Tim

you could just modify the standard asset camera script “Mouse Orbit”. Just copy paste the code to a new script and change

function LateUpdate () {
    if (target) {
        x += Input.GetAxis("Mouse X") * xSpeed * 0.02;
        y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;
 		
 		y = ClampAngle(y, yMinLimit, yMaxLimit);
 		       
        var rotation = Quaternion.Euler(y, x, 0);
        var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
        
        transform.rotation = rotation;
        transform.position = position;
    }
}

to

function LateUpdate () {
    if (target) {
        x += Input.GetAxis("Horizontal") * xSpeed * 0.02;
        
 		       
        var rotation = Quaternion.Euler(0, x, 0);
        var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
        
        transform.rotation = rotation;
        transform.position = position;
    }
}

Awesome :smile:
The answer was right before me :stuck_out_tongue:
Great Thanks to you Slem! :lol:

  • Tim