Question by
A4B4 · Sep 23, 2021 at 02:08 AM ·
camera-movementcamera rotate
How to lock x camera rotation to constant
I tried to make the x rotation 45 instead of 0 on the camera but it always did a calculation for some reason so I deleted it and this is the code without any x lock
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class cameraMovement : MonoBehaviour
{
[SerializeField] private Camera cam;
[SerializeField] private Transform pivotTarget;
private Vector3 previousPosition;
void Update()
{
if (Input.GetMouseButtonDown(1))
{
previousPosition = cam.ScreenToViewportPoint(Input.mousePosition);
}
if(Input.GetMouseButton(1))
{
Vector3 direction = previousPosition - cam.ScreenToViewportPoint(Input.mousePosition);
cam.transform.position = pivotTarget.position;
cam.transform.Rotate(new Vector3(0, 0, 0), direction.x * 180);
cam.transform.Rotate(new Vector3(0, 1, 0), -direction.x * 180, Space.World);
cam.transform.Translate(new Vector3(0, 10, -10));
previousPosition = cam.ScreenToViewportPoint(Input.mousePosition);
Debug.Log(previousPosition.x);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Roll a ball camera rotation on Q and E 0 Answers
Rotate Around Function not working as intended 1 Answer
CineMachine Camera Movement is inverse 1 Answer
Relative movement isn't changing based on camera orientation. 0 Answers
getting Jittery movement on camera when player rotating and moving in same time 0 Answers