- Home /
How can I create vertical camera movement?,How can I make vertical camera movement?
I have recently begun following a tutorial to create a first person shooter. I have finished camera movement, which the tutorial says should also have verticality. I know this is true because there is a way of manually setting a Y value to the script. I am completely stumped for what to do here.
Here is my script: using UnityEngine;
public class CameraMovement : MonoBehaviour { private GameObject player; private float minClamp = -90; private float maxClamp = 90; public Vector2 rotation; private Vector2 currentLookRot; private Vector2 rotationV = new Vector2(0, 0); public float lookSensitivity = 2; public float lookSmoothDamp = 0.1f;
// Start is called before the first frame update
void Start()
{
//Access the Player GameObject
player = transform.parent.gameObject;
}
// Update is called once per frame
void Update()
{
//Player input from the mouse
rotation.y = Mathf.Clamp(rotation.y, minClamp, maxClamp);
//Rotate the character around based on the mouse X position
player.transform.RotateAround(transform.position, Vector3.up, Input.GetAxis("Mouse X") * lookSensitivity);
//Smooth the current Y rotation for looking up and down.
currentLookRot.y = Mathf.SmoothDamp(currentLookRot.y, rotation.y, ref rotationV.y, lookSmoothDamp);
//Update the camera X rotation based on the values generated.
transform.localEulerAngles = new Vector3(-currentLookRot.y, 0, 0);
}
} ,I have been following a tutorial to crate a simple FPS, however I have run into some problems with camera control. The tutorial says that I should be able to move the camera vertically, and there is a method of manually typing in vertical rotation, but I cannot move it vertically in - game. Here is my script:
using UnityEngine;
public class CameraMovement : MonoBehaviour { private GameObject player; private float minClamp = -90; private float maxClamp = 90; public Vector2 rotation; private Vector2 currentLookRot; private Vector2 rotationV = new Vector2(0, 0); public float lookSensitivity = 2; public float lookSmoothDamp = 0.1f;
// Start is called before the first frame update
void Start()
{
//Access the Player GameObject
player = transform.parent.gameObject;
}
// Update is called once per frame
void Update()
{
//Player input from the mouse
rotation.y = Mathf.Clamp(rotation.y, minClamp, maxClamp);
//Rotate the character around based on the mouse X position
player.transform.RotateAround(transform.position, Vector3.up, Input.GetAxis("Mouse X") * lookSensitivity);
//Smooth the current Y rotation for looking up and down.
currentLookRot.y = Mathf.SmoothDamp(currentLookRot.y, rotation.y, ref rotationV.y, lookSmoothDamp);
//Update the camera X rotation based on the values generated.
transform.localEulerAngles = new Vector3(-currentLookRot.y, 0, 0);
}
}
Answer by bad_at_unity · Aug 22, 2020 at 03:56 PM
Answers is broken... It said that everything had been deleted. Sorry.
Your answer
Follow this Question
Related Questions
Camera defaulting to -90 Y 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to get A Camera Collision? 1 Answer