Orbit Camera with mouse drag, locked at x rotation?
Hey, I'm making a camera that rotates around a specific object. It has transform.LookAt so it's always looking at the object specifically, and it'll rotate in a circle around said object.
I want to make it so when I click and drag left it will rotate the camera to the right, and vice versa. If you need an example, check out the camera from "Viridi". No y camera rotation, though!
time.deltatime is obviously a placeholder, I want to change the whole orbitx block to be an input for mousedrag, but unity has no advanced "if mouse drag (left)", and I havent found an easy solution so far.
Anyway, here's the code.
using UnityEngine;
using System.Collections;
public class CameraOrbit : MonoBehaviour
{
public GameObject target = null;
public bool orbitX = false;
void Update()
{
if (target != null)
{
transform.LookAt(target.transform);
if (orbitX)
{
transform.RotateAround(target.transform.position, Vector3.up, Time.deltaTime);
}
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612093248im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Move a object around another object 0 Answers
Orbit position controlled by mouse 2D (C#) 0 Answers
C# 360 Orbital Camera Controller (Gimbal Lock Issue) 1 Answer
Move a object around another object 0 Answers
Camera drag move 0 Answers