I’ve been trying to make the camera move with my mouse pointer, so that I can look around with the camera. I’ve tried multiple ways of doing this although all of them were using Transform (using Rotate and rotation but I found LookAt to be the simplest and has the same results) . And I keep on getting the same problem, the camera never wants to rotate at the y axis, not without glitching out at least. X axis works decently fine, I know this code isn’t perfect and awfully simple but I’m still dumbstruck to why the y axis isn’t rotating at all like the x axis is. I have no clue at all to why this is happening.
It’s probably due to my horrible code and horrible knowledge of unity (and coding in general) but help would be very much appreciated… as I have no clue to why this isn’t working. (A reply that explains why and tells me how I’m wrong is also very much appreciated!) Also it might be important to mention that the “main camera” is a child to the “player” (which is where the script is assigned to), and the “player” it’s self is a child to “PlayerMain” which is just an empty gameObject. Thanks for all help!
public class LookAroundScript : MonoBehaviour {
//Making variablas with type of Transform
Transform cameraTransform;
//Getting the GameObjects
public GameObject theCamera;
Vector3 mouseCord;
void Update()
{
//Getting the transform compenent
cameraTransform = theCamera.GetComponent<Transform>();
//Recording the position of the mouse
mouseCord = Input.mousePosition;
//Seeing the coordinates
Debug.Log(mouseCord);
//Making the camera rotate to the mouseCords
cameraTransform.LookAt(mouseCord);
}
}