RotateAround Camera .... Failing ?!

Hey Guys,

I’ve created a Camera and a cube. Now I would really like to rotate the cam around the center of the cube. So I tried to use rotate.Around… but It doesnt work.

The Code is about:

	if(Input.mousePosition.x < (Screen.width / 20)){
  transform.RotateAround(target.transform.position, Vector3.up,1);
}
    if(Input.mousePosition.x > (Screen.width / 20 * 19)){
  transform.RotateAround(target.transform.position, Vector3.up,1);
}
    if(Input.mousePosition.Y < (Screen.width / 10)){
  transform.RotateAround(target.transform.position, Vector3.right,1);
}
    if(Input.mousePosition.Y > (Screen.width / 10 * 9)){
  transform.RotateAround(target.transform.position, -Vector3.right,1);
}

The rotation horizontaly works perfect… really nice. In the vertical I’ve got a huge problem… maybe you can try your own, to know what I mean. I know why it so, because the “Vector3.right” doesnt is the right rotation at every time. So sometimes Vector3.forward works good, sometimes Vector3.right… depending on where I’m in the orbit.

Do you have an solution for this problem ??

Thanks a lot

tobi

This is just how I’ve done it- everybody is going to have a different method. I have a 3d modeling background, so I’m used to cameras having three parts: A root, A camera, and a Target.

Basically, I create an empty game object and call it CameraRoot, then parent the camera to it. I use CameraRoot to handle all rotations. The only time the actual camera moves is in local Z (for zooming in and out). The target is whatever you want to look at. For my third-person system, I keep my camera’s root on the player, that way to orbit around them all I have to do is rotate the root on eulerAngles.y

Hopefully that made sense, it’s actually a pretty simple setup but it gives you a lot more control with your camera.