This is great! One question, when I try to rotate underneath the gameobject, I get a weird behavior where the camera jitters and flips. Is there a way to fix this?
@firedragongamestudio4 ай бұрын
OH... good focus! that's actually a perfect example for a gimbal lock 😶🌫 idk why i never tested this... anyway, here is a script to avoid gimbal lock, using Quaternion for rotation, instead of Vector3 😃 using UnityEngine; public class OrbitCamera : MonoBehaviour { [SerializeField] private Transform target; [SerializeField] private float sensitivity = 5f; [SerializeField] private float orbitRadius = 5f; [SerializeField] private float minimumOrbitDistance = 2f; [SerializeField] private float maximumOrbitDistance = 10f; private float yaw; private float pitch; void Start() { yaw = transform.eulerAngles.y; pitch = transform.eulerAngles.x; } void Update() { if (Input.GetMouseButton(0)) { float mouseX = Input.GetAxis("Mouse X"); float mouseY = Input.GetAxis("Mouse Y"); yaw += mouseX * sensitivity; pitch -= mouseY * sensitivity; transform.rotation = Quaternion.Euler(pitch, yaw, 0); } orbitRadius -= Input.mouseScrollDelta.y / sensitivity; orbitRadius = Mathf.Clamp(orbitRadius, minimumOrbitDistance, maximumOrbitDistance); transform.position = target.position - transform.forward * orbitRadius; } }
@ahwendorf24 ай бұрын
@@firedragongamestudio Thank you very much for your prompt and helpful reply! I did not know about gimble lock. Now it rotates all the way around on the x-axis as desired! :D However, now it is doing something else odd. When it is on the "back" (x-rotation between -90 and 90) then the side-to-side rotation is reversed. Any idea how to fix that?
@firedragongamestudio4 ай бұрын
@@ahwendorf2 Just invert the raw X input, when in a certain range of rotation. Smth like this should work: using UnityEngine; public class OrbitCamera : MonoBehaviour { [SerializeField] private Transform target; [SerializeField] private float sensitivity = 5f; [SerializeField] private float orbitRadius = 5f; [SerializeField] private float minimumOrbitDistance = 2f; [SerializeField] private float maximumOrbitDistance = 10f; private float yaw; private float pitch; void Start() { yaw = transform.eulerAngles.y; pitch = transform.eulerAngles.x; } void Update() { if (Input.GetMouseButton(0)) { float mouseX = Input.GetAxis("Mouse X"); float mouseY = Input.GetAxis("Mouse Y"); pitch -= mouseY * sensitivity; bool isUpsideDown = pitch > 90f || pitch < -90f; // Invert yaw input if the camera is upside down if (isUpsideDown) { yaw -= mouseX * sensitivity; } else { yaw += mouseX * sensitivity; } transform.rotation = Quaternion.Euler(pitch, yaw, 0); } orbitRadius -= Input.mouseScrollDelta.y / sensitivity; orbitRadius = Mathf.Clamp(orbitRadius, minimumOrbitDistance, maximumOrbitDistance); transform.position = target.position - transform.forward * orbitRadius; } }
@stevendalton69528 ай бұрын
I signed up for the highest tier. Can I get the script?
@firedragongamestudio8 ай бұрын
Sure, check out the channel community tab. There is a post for posting Github usernames. I can share the code either directly in the comments there, or send you a link for a Repo. 🙂
@firedragongamestudio7 ай бұрын
Are you still interested? You haven't sent me your Github username, for code sharing yet.
@anotherangle3dvisuals60810 ай бұрын
And can you please provide us with the script? Thanks!
@firedragongamestudio10 ай бұрын
As mentioned in the video, direct source code access is only available for channel members, but you can pause the video and just type it from the screen :)
@anotherangle3dvisuals60810 ай бұрын
@@firedragongamestudioNo worries. Thanks. Are you perhaps available for custom c# Unity coding? Contact me, thanks.