I made a very simple mouse look script that I attached to Main Camera. The mouse wheel zooms in an out and when the right mouse button is pressed you can pan right and left. So your camera can be facing 45 degrees left while your avatar is running straight ahead. Here’s the problem…
The third person controller script detects the camera is off and starts to turn your avatar in that direction. So I cracked open that script hoping to find a section of code where the right mouse button was depressed and just rem that out. Well, I didn’t and I’m not there yet to modify this script, I need more learning. Are there any third person scripts out there that can do this. Here is my simple script that I attached to the main camera in the thrid person camera
using UnityEngine;
using System.Collections;
public class rotoMouseLook : MonoBehaviour
{
public Vector3 v3CameraPosition; //the local rotation
public Vector3 v3CameraRotation; //the local rotation
public float fRightMouseButton;
private float fCameraHStep = 0.2f;
private float fCameraVStep = 0.05f;
void Start()
{
v3CameraPosition.z = transform.localPosition.z;
v3CameraPosition.y = transform.localPosition.y;
v3CameraRotation.x = transform.eulerAngles.x;
v3CameraRotation.y = transform.eulerAngles.y;
v3CameraRotation.z = transform.eulerAngles.z;
}
void Update()
{
// mouse - cam elevation
float fScrollWheel = Input.GetAxis("Mouse ScrollWheel");
fRightMouseButton = Input.GetAxis("Mouse X");
//zoom in - mouse scroll up (forward)
//===========================================
if (fScrollWheel > 0)
{
//horizontal in
if(v3CameraPosition.z < 0f)
v3CameraPosition.z += fCameraHStep;
//vertical in
if (v3CameraPosition.y > 0.5f)
v3CameraPosition.y -= fCameraVStep;
}
//===========================================
//zoom out - mouse scroll down (backwards)
//===========================================
if (fScrollWheel < 0)
{
//horizontal out
if(v3CameraPosition.z > -10f)
v3CameraPosition.z -= fCameraHStep;
//vertical out
if (v3CameraPosition.y < 2.5f)
v3CameraPosition.y += fCameraVStep;
}
//===========================================
//pan - right mouse button
//===========================================
if (Input.GetMouseButton(1))
{
//pan to the right
if(fRightMouseButton > 0)
{
v3CameraRotation.y += fRightMouseButton * 5; //fRightMouseButton is positive
if (v3CameraRotation.y >= 360)
v3CameraRotation.y -= 360;
}
//pan to the left
if (fRightMouseButton < 0)
{
v3CameraRotation.y += fRightMouseButton * 5; //fRightMouseButton is negative
if (v3CameraRotation.y <= -360)
v3CameraRotation.y += 360;
}
}
//===========================================
//move the camera to it's new position & rotation
//===========================================
v3CameraPosition.x = transform.localPosition.x;
transform.localPosition = v3CameraPosition;
v3CameraRotation.x = transform.eulerAngles.x;
v3CameraRotation.z = transform.eulerAngles.z;
transform.localEulerAngles = v3CameraRotation;
//===========================================
}
}