Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Let us know your feedback about the Global Illumination changes in the 2023.2 beta.
    Dismiss Notice
  3. Dismiss Notice

[5.5.0b11] Imported asset: cameras; and free look camera rotation with a mouse isn't working.

Discussion in '5.5 Beta' started by bhunterd, Nov 15, 2016.

  1. bhunterd

    bhunterd

    Joined:
    Oct 6, 2016
    Posts:
    27
    Can't rotate camera with a mouse. It work in 5.5.0b5 also in 5.4.2f2 but not in 5.5.0b11:

    using System;
    using UnityEngine;
    using UnityStandardAssets.CrossPlatformInput;

    namespace UnityStandardAssets.Cameras
    {
    publicclassFreeLookCam:pivotBasedCameraRig
    {
    //Thisscriptisdesignedtobeplacedontherootobjectofacamerarig,
    //comprising3gameobjects,eachparentedtothenext:

    //Camera Rig
    // Pivot
    // Camera

    [SerializeField]privatefloatm_MoveSpeed=1f;//Howfasttherigwillmovetokeepupwiththetarget'sposition.
    [Range(0f,10f)][SerializeField]privatefloatm_TurnSpeed=1.5f;//Howfasttherigwillrotatefromuserinput.
    [SerializeField]privatefloatm_TurnSmoothing=0.0f;//Howmuchsmoothingtoapplytotheturninput,toreducemouse-turn jerkiness
    [SerializeField]privatefloatm_TiltMax=75f;//Themaximumvalueofthexaxisrotationofthepivot.
    [SerializeField]privatefloatm_TiltMin=45f;//Theminimumvalueofthexaxisrotationofthepivot.
    [SerializeField]privateboolm_LockCursor=false;//Whetherthecursorshouldbehiddenandlocked.
    [SerializeField]privateboolm_VerticalAutoReturn=false;//setwetherornottheverticalaxisshouldauto return

    privatefloatm_LookAngle;//Therig'syaxisrotation.
    privatefloatm_TiltAngle;//Thepivot'sxaxisrotation.
    privateconstfloatk_LookDistance=100f;//Howfarinfrontofthepivotthecharacter'slooktargetis.
    privateVector3m_PivotEulers;
    privateQuaternionm_PivotTargetRot;
    privateQuaternionm_TransformTargetRot;

    protectedoverridevoidAwake()
    {
    base.Awake();
    //Lockorunlockthecursor.
    Cursor.lockState=m_LockCursor?CursorLockMode.Locked:CursorLockMode.None;
    Cursor.visible= !m_LockCursor;
    m_PivotEulers=m_Pivot.rotation.eulerAngles;

    m_PivotTargetRot=m_Pivot.transform.localRotation;
    m_TransformTargetRot=transform.localRotation;
    }


    protectedvoidUpdate()
    {
    HandleRotationMovement();
    if(m_LockCursor&&Input.GetMouseButtonUp(0))
    {
    Cursor.lockState=m_LockCursor?CursorLockMode.Locked:CursorLockMode.None;
    Cursor.visible= !m_LockCursor;
    }
    }


    privatevoidOnDisable()
    {
    Cursor.lockState=CursorLockMode.None;
    Cursor.visible=true;
    }


    protectedoverridevoidFollowTarget(floatdeltaTime)
    {
    if(m_Target==null)return;
    //Movetherigtowardstargetposition.
    transform.position=Vector3.Lerp(transform.position,m_Target.position,deltaTime*m_MoveSpeed);
    }


    privatevoidHandleRotationMovement()
    {
    if(Time.timeScale<float.Epsilon)
    return;

    //Readtheuser input
    varx=CrossPlatformInputManager.GetAxis("MouseX");
    vary=CrossPlatformInputManager.GetAxis("MouseY");

    //Adjustthelookanglebyanamountproportionaltotheturnspeedandhorizontalinput.
    m_LookAngle+=x*m_TurnSpeed;

    //Rotatetherig(therootobject)aroundYaxisonly:
    m_TransformTargetRot=Quaternion.Euler(0f,m_LookAngle,0f);

    if(m_VerticalAutoReturn)
    {
    //Fortiltinput,weneedtobehavedifferentlydependingonwhetherwe'reusingmouseortouchinput:
    //onmobile,verticalinputisdirectlymappedtotiltvalue,soitspringsbackautomaticallywhenthelookinputis released
    //wehavetotestwhetheraboveorbelowzerobecausewewanttoauto-returntozeroevenifminandmaxarenotsymmetrical.
    m_TiltAngle=y>0?Mathf.Lerp(0,-m_TiltMin,y):Mathf.Lerp(0,m_TiltMax,-y);
    }
    else
    {
    //onplatformswithamouse,weadjustthecurrentanglebasedonYmouseinputandturn speed
    m_TiltAngle-=y*m_TurnSpeed;
    //andmakesurethenewvalueiswithinthetilt range
    m_TiltAngle=Mathf.Clamp(m_TiltAngle,-m_TiltMin,m_TiltMax);
    }

    //TiltinputaroundXisappliedtothepivot(thechildofthisobject)
    m_PivotTargetRot=Quaternion.Euler(m_TiltAngle,m_PivotEulers.y,m_PivotEulers.z);

    if(m_TurnSmoothing>0)
    {
    m_Pivot.localRotation=Quaternion.Slerp(m_Pivot.localRotation,m_PivotTargetRot,m_TurnSmoothing*Time.deltaTime);
    transform.localRotation=Quaternion.Slerp(transform.localRotation,m_TransformTargetRot,m_TurnSmoothing*Time.deltaTime);
    }
    else
    {
    m_Pivot.localRotation=m_PivotTargetRot;
    transform.localRotation=m_TransformTargetRot;
    }
    }
    }
    }
     

    Attached Files:

  2. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,104
    Hi bhunterd,
    Thank you for reporting this. Could you also file a bug report together with a minimal reproduction case please and reply with the issue # in this thread?
     
  3. bhunterd

    bhunterd

    Joined:
    Oct 6, 2016
    Posts:
    27
    Probably project was damaged (in export from 5.5.0b5 to 5.5.0b11), I copy past asset floder to a new project and camera work, and exported similar from 5.4.2f2 to 5.50b11 and it work too.
     
    LeonhardP likes this.