- Home /
Unity 5 new first person mouse look doesn't look up and down
I update my project to the new unity 5 and can't seem to fix the new mouse look script that doesn't allow you to look up and down only left and right how would I fix this error tried to fix it myself for that past week haven't make any progress.
@Rainkiller27 please dont post Questions and Comments as answers.
Answer by Aurecon_Unity · Feb 03, 2017 at 09:00 PM
Perhaps you've solved this issue already but I just found that my FPS Controller standard asset stops allowing me to look up and down (rotate on the x-axis) when in player settings I have 'Virtual Reality Supported' selected.
In this case I wasn't building something for VR but SteamVR still kicked in when I pressed play and VR supported was automatically selected because you can now use any camera as a VR camera.
Sneaky little settings change, look out for it.
Thankyou so much for your answer. I would have given up on this one! :)
Thanks! This worked for me in 2017.2. I was looking in all sorts of other places.
Answer by NFMynster · Feb 20, 2016 at 06:29 AM
If you import the "Standard Assets->Characters", then you'll get a FPSController prefab which should be ready to use. Edit, that script is getting its camera reference from the main camera, so make sure there is only one camera with the "main camera" tag.
That what I have atm, but it's only allowing left and right
Answer by Shykeas · Feb 20, 2016 at 10:13 AM
Please load your script in. Possibilities are it's programmed to look among Input named "Horizontal" but not Vertical. Or Vertical is there but your Unity project doesn't have such a name of an input. Etc. Either way, we can't solve an issue that we can't inspect.
It's just the standard asset Character. here is the code though
using System;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
namespace UnityStandardAssets.Characters.FirstPerson
{
[Serializable]
public class $$anonymous$$ouseLook
{
public float XSensitivity = 2f;
public float YSensitivity = 2f;
public bool clampVerticalRotation = true;
public float $$anonymous$$inimumX = -90F;
public float $$anonymous$$aximumX = 90F;
public bool smooth;
public float smoothTime = 5f;
private Quaternion m_CharacterTargetRot;
private Quaternion m_CameraTargetRot;
public void Init(Transform character, Transform camera)
{
m_CharacterTargetRot = character.localRotation;
m_CameraTargetRot = camera.localRotation;
}
public void LookRotation(Transform character, Transform camera)
{
float yRot = CrossPlatformInput$$anonymous$$anager.GetAxis("$$anonymous$$ouse X") * XSensitivity;
float xRot = CrossPlatformInput$$anonymous$$anager.GetAxis("$$anonymous$$ouse Y") * YSensitivity;
m_CharacterTargetRot *= Quaternion.Euler (0f, yRot, 0f);
m_CameraTargetRot *= Quaternion.Euler (-xRot, 0f, 0f);
if(clampVerticalRotation)
m_CameraTargetRot = ClampRotationAroundXAxis (m_CameraTargetRot);
if(smooth)
{
character.localRotation = Quaternion.Slerp (character.localRotation, m_CharacterTargetRot,
smoothTime * Time.deltaTime);
camera.localRotation = Quaternion.Slerp (camera.localRotation, m_CameraTargetRot,
smoothTime * Time.deltaTime);
}
else
{
character.localRotation = m_CharacterTargetRot;
camera.localRotation = m_CameraTargetRot;
}
}
Quaternion ClampRotationAroundXAxis(Quaternion q)
{
q.x /= q.w;
q.y /= q.w;
q.z /= q.w;
q.w = 1.0f;
float angleX = 2.0f * $$anonymous$$athf.Rad2Deg * $$anonymous$$athf.Atan (q.x);
angleX = $$anonymous$$athf.Clamp (angleX, $$anonymous$$inimumX, $$anonymous$$aximumX);
q.x = $$anonymous$$athf.Tan (0.5f * $$anonymous$$athf.Deg2Rad * angleX);
return q;
}
}
}
Answer by Eno-Khaon · Feb 20, 2016 at 10:19 AM
If you're using just the script alone, it's fundamentally based around a two-piece system.
Left and right, by its intended scheme, rotate the character around the Y-axis. Up and down, however, rotate the camera on the X-axis instead. By rotating the camera rather than the character, this prevents the character from leaning and, if physics is set to take over, falling over.
Based around that script as well, be certain that it is set in the inspector to permit rotation both horizontally and vertically, ensure that proper rotational limits have been placed on the rotation, and then confirm that it's properly connecting the script to the character's camera and not to any other(s).
This new mouselook doesn't allow you to connect it to the camera only the player since the mouselook is built in to the first person controller not sure if they updated it but in the mouselook script doesn't have the Y-axis anymore only the X-axis.
Hmm... Looking at your other comment, I'm not sure where the functions are being called from, but it appears that "Init()" is the first place where a camera's Transform is being utilized by the script.
Whichever script is supposed to be passing that data along could have more to do with it at this point, since it would pass in the Transform arguments for the functions (for instance, in "LookRotation()" where the rotation is actually being applied.
camera.localRotation = Quaternion.Slerp (camera.localRotation, m_CameraTargetRot, smoothTime * Time.deltaTime);
Your answer
![](https://koobas.hobune.stream/wayback/20220612064828im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Make a script begin its action OnTriggerEnter? Please help. 1 Answer
Unity how to access a static variable from the FirstPersonController component 2 Answers
Can I make a CharacterController slide UPhill? 1 Answer
access first person controller from other script 0 Answers
Drag to look instead of right joystick 0 Answers