Not exactly doing what is supposed to do, i wanted the camera to follow the mouse smoothly, instead its kind of stuck and moving softly only on a zone.
i dont get right the quaternion stuff, i supose i could use a hand here. thanks.
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
Ray ray2 = Camera.main.ScreenPointToRay(Vector3.up);
RaycastHit hit;
RaycastHit hit2;
Physics.Raycast(ray, out hit, Mathf.Infinity);
Physics.Raycast(ray2, out hit2, Mathf.Infinity);
Vector3 diferencia = hit2.point - hit.point;
Quaternion targetRotation = Quaternion.FromToRotation(hit.point, hit2.point);
Camera.main.transform.rotation = Quaternion.Lerp(Camera.main.transform.rotation, targetRotation, speed * Time.deltaTime);
,well, this is kind of my script, its C#.
It works weird, doesnt follow the mouse correctly, and always looks at the same zone, not going around to much, im not very good at this, just started to learn, can anyone help me a bit on this script?
Thank you
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
Ray ray2 = Camera.main.ScreenPointToRay(Vector3.up);
RaycastHit hit;
RaycastHit hit2;
Physics.Raycast(ray, out hit, Mathf.Infinity);
Physics.Raycast(ray2, out hit2, Mathf.Infinity);
Vector3 diferencia = hit2.point - hit.point;
Quaternion targetRotation = Quaternion.FromToRotation(hit.point, hit2.point);
Camera.main.transform.rotation = Quaternion.Lerp(Camera.main.transform.rotation, targetRotation, speed * Time.deltaTime);
What i tried to do, is to cast 2 rays, one from the camera to the screen position, and one from the camera straight forward, then get the diference between those two points and i would have found the rotation i needed, but i dont understand much the quaternion thingsā¦