I have found several awnsers to this question online, and I have tried all of them, but they either break my camera, or just overall don't work.
Here is my script:
using UnityEngine;
using System.Collections;
public class fp : MonoBehaviour
{
public float speedH = 2.0f;
public float speedV = 2.0f;
private float yaw = 0.0f;
private float pitch = 0.0f;
void Update()
{
yaw += speedH * Input.GetAxis("Mouse X");
pitch -= speedV * Input.GetAxis("Mouse Y");
transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
}
}
As far as I know, there is 3 solutions to this problem, but I don't know how to implement any of the solutions
Solution 1: Convert the script above to Unityscript (I have little expirience with C#) and I can solve the problem with "if" statements.
Solution 2: Provide the C# code to limit the angle on my script to an angle of 90 degrees all axis
Solution 3: All of the above
There is no attempt to limit any axis in your code. Use a temporary variable to limit your axis by incrementing it each tome
Input.GetAxis
changes. If it reaches the min or max value you want to limit it to then theMathf.Clamp
to clamp it between that min and max values/angle.Modified this to limit your FPS camera in both axis instead of usual y-axis limit.
You don't post what you've tried, so this is a shot in the dark on helping you. Check Unity's Mathf.Clamp to restrict the angles allowed.