Search code examples
c#unity-game-enginegame-physics

Unity3D: How can I make the camera rotate around an object, with an angle on the camera, only on x-axis, by right-mousebutton drag?


I am making a game in Unity3D, I'm stuck because I want to make the Main camera, being able to be dragged with right-mousebutton.

I have already tried some codes that fundamentally work, but the "Orbit" rotation is doing the rotation relative to the rotation of the camera itself.

So what I want to, is to make the camera rotate around an object, on right-mousebutton drag, while the camera is looking down on the object, and still is able to rotate around the object, with a linear orbit?

How can I do this? need help for real!


Solution

  • Attach the camera to an empty game object by making it a child and rotate that instead. You can then place your camera anywhere in the scene at any rotation and when you rotate the parent object, it will orbit that point.