I am trying to make an OG Doom like game and I implemented that you can look around but I was trying to add it to look up and down but it would just go till the half way point/the horizon and then stuck. It won't go above -90 on X axis.
using System.Net.Http.Headers;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerController : MonoBehaviour
{
public Rigidbody2D theRB;
public float moveSpeed =5f;
private Vector2 moveInput;
private Vector2 mouseInput;
public float mouseSensitivity = 2f;
public Transform viewCam;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
// player movement
moveInput = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
Vector3 moveHorizontal = transform.up * moveInput.y;
Vector3 moveVertical = transform.right * moveInput.x;
theRB.velocity = (moveHorizontal + moveVertical) * moveSpeed;
//player view control
mouseInput = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y")) * mouseSensitivity;
transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, transform.rotation.eulerAngles.z - mouseInput.x);
viewCam.localRotation = Quaternion.Euler(viewCam.localRotation.eulerAngles - new Vector3(mouseInput.y, 0f, 0f));
}
}
This is the code that i am trying to use to make it work but it is not working. I have tried changing other values but it's getting wacky. I just want to know if there is a way to make it look above the horizon
You should read about eulerAngles and why in many cases it is not reliable to use it. In your case viewCam.localRotation
might return something very different from what you assigned the frame before. Also Euler angles are open for gimbal locks!
Instead rather use e.g.
transform.rotation *= Quaternion.Euler(0, 0, -mouseInput.x);
viewCam.localRotation *= Quaternion.Euler(-mouseInput.y, 0f, 0f);