Mouse Look Script

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;
        //===========================================
    }

}

You might want to try parenting a new game object to the Third Person controller, and hanging your camera on their with your own control script.

Then you can modify the TPC to delete its camera-adjusting portion and your script would be the only thing doing the work.

If you still want some features of the TPC camera (I’m not sure what all they are), then you would have to either a) rewrite those features in your script, or b) copy/paste them into your script, or c) make sure you don’t delete that functionality in step #2 above.

Creative idea, but it failed. he still turned, plus camera wouldn’t fall, so I added gavity and it fell through terrain. so then I added collider and it collided with itself. I spaced them out just for testing.

Geez, I was actually looking at the wrong script to edit. I should be looking at the “Third Person User Control”. It’s pretty simple script. I am hoping I can swap out the reference of the camera with a reference to just the avatar.

Yup, nailed it. All I had to do is remove the reference to main camera and replace it with the “transform” Here is the modified “Third Person User Control” script. Now I can pan left and right with out my avatar turning

using System;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;

namespace UnityStandardAssets.Characters.ThirdPerson
{
    [RequireComponent(typeof(ThirdPersonCharacter))]
    public class ThirdPersonUserControl : MonoBehaviour
    {

        private ThirdPersonCharacter m_Character; // A reference to the ThirdPersonCharacter on the object
        private Vector3 m_CamForward;             // The current forward direction of the camera
        private Vector3 m_Move;
        private bool m_Jump;                      // the world-relative desired move direction, calculated from the camForward and user input.


        private void Start()
        {
            // get the third person character ( this should never be null due to require component )
            m_Character = GetComponent<ThirdPersonCharacter>();
        }


        private void Update()
        {
            if (!m_Jump)
            {
                m_Jump = CrossPlatformInputManager.GetButtonDown("Jump");
            }
        }


        // Fixed update is called in sync with physics
        private void FixedUpdate()
        {
            // read inputs
            float h = CrossPlatformInputManager.GetAxis("Horizontal");
            float v = CrossPlatformInputManager.GetAxis("Vertical");
            bool crouch = Input.GetKey(KeyCode.C);

            // calculate move direction to pass to character

            // calculate camera relative direction to move:
            m_CamForward = Vector3.Scale(transform.forward, new Vector3(1, 0, 1)).normalized;
            m_Move = v * m_CamForward + h * transform.right;

#if !MOBILE_INPUT
            // walk speed multiplier
            if (Input.GetKey(KeyCode.LeftShift)) m_Move *= 0.5f;
#endif

            // pass all parameters to the character control script
            m_Character.Move(m_Move, crouch, m_Jump);
            m_Jump = false;
        }
    }
}

here is a video of the free look pan