- Home /
Question by
priyansh3110 · Aug 11, 2021 at 07:02 PM ·
script.camera-lookclampcamera rotation
fps movement limited horizontal and vertical both
hii guys .. i want to make a like my solder stand and fire a MG .. its a defendre game and i want to he can shoot a limited area he cant turn around so plz can anyone help me to clamp camera rotation horizontal and vertical m not good in scripting but here is my script sorry my english is very bad
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class mouselook : MonoBehaviour { public float sencivity;
public Transform player;
private float rot;
private float rot2;
private void Update()
{
float x = Input.GetAxis("Mouse X") * sencivity * Time.deltaTime;
float y = Input.GetAxis("Mouse Y") * sencivity * Time.deltaTime;
rot -= y;
rot = Mathf.Clamp(rot, -40f, 15f);
transform.localRotation = Quaternion.Euler(rot, 0f, 0f);
player.Rotate(player.up * x);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613041533im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Camera gets stuck when cursor is locked 0 Answers
How to Lerp and Clamp 1 Answer
Problem with Unity’s FPSController camera 2 Answers
Simple Camera ZoomIn Out Script 1 Answer
how can i rotate the camera around the object , which follows the object??? 0 Answers