(second try, failed the first one, going for a shorter version)
Hello guys! I am trying to achieve a camera rotation around a static object, using a mouse (and orbital rotation).
On the horizontal Axis, of 360° and on the vertical axis from 0 to 180°.
I am struggling on this one since the morning, and I probably went on a tunnel vision for most on the day. Posting here is like breathing fresh air.
So far, I do have a rotation. But a weird one, on horizontal axis not matter where in move my mouse to (up, down, left right : the rotation happen from left to right, sometimes from right to left, almost “laggy”).
I know that rotate around is the way but I have probably missed something resulting in such headaches (for “not that much”)
I am off work for the moment, and will be able to provide some screens of my work later in the morning.
For the moment, if you have any advices, I am listening.
The rotation is not in one direction only, not laggy anymore but still not as wanted : it is happening whenever I move to mouse, whatever the direction is (.gif of it : https://imgur.com/a/1om7kZG). Tbh I am kinda lost right now, bumping (again) my head against the walls.
EDIT_1 : both rotations are working fine, but I need to clamp the Y axis rotation (max 90° for exemple). And I am stuck again, missing something. Kinda driving me crazy as it seems to be “a simple thing to do”.
EDIT_2 : thx to Nuverian, it is working!
The RotateAround method does not really work well with clamping. It is a pre-canned Unity method that unless you make it really complex or rewrite the method, it best works without clamp (techincally that is because it also modify the position of the object instead of only its rotation).
As such, I would suggest to use a direct approach for setting the rotation of an object. For this to work, you will need to have the Camera parented to an object that you want to be the “targetOfCamera” basically, and have that target object rotate instead (and as such make the camera rotate around it since the camera is parented to that object).
Note that the “min” and “max” values of Mathf.Clamp method should be within positive range (0 – 360) for this to work, otherwise more complex script is required
The working flowscript, tuned for my needs (I still need to tune it a bit more and then, I will drop the flowscript.asset) :