hey guys =)
im working on a camera script and got some issues with the camera rotation around a GameObject, especially with the vertical rotation. The camera should rotate when the right mouse button is pressed.
the horizontal rotation works fine with this:
transform.RotateAround( avatarTransform.position, Vector3.up, rotationSpeed * Time.deltaTime * Input.GetAxisRaw( "Mouse X" ) );
then i started the vertical rotation with this:
Vector3 relativePos = avatarTransform.position - transform.position; // Vector from camera to player
Vector3 relativePosRight = new Vector3( -relativePos.z, relativePos.y, relativePos.x ); // right vector of the vector above
transform.RotateAround( avatarTransform.position, relativePosRight, rotationSpeed * Time.deltaTime * Input.GetAxisRaw( "Mouse Y" ) );
but the camera doesnt rotate around the object just vertically. it rotates also to the right, and goes directly below the avatar and stops there ( sry for this bad explanation, but dont know how to say it otherwise ).
then i tried it with this code:
transform.LookAt( avatarTransform.position );
Vector3 rotation = new Vector3( Input.GetAxisRaw( "Mouse X" ), Input.GetAxisRaw( "Mouse Y" ), 0 );
transform.Translate( rotation * Time.deltaTime * rotationSpeed );
it works, but its kinda … laggy. i mean its not like the fps are going down, but the camera movement is shaky when it does the LookAt every frame.
so … any ideas how to solve the vertical rotation ?