- Home /
Problems with 3d Top-Down Camera
Im using cinemachine to create a 3d Top-Down camera for a project that also rotates when the player rotates but it behaves very oddly and auto-rotates infinitely when it shouldn't. I followed a tutorial thats uses a mouse position raycast to player plane so the player rotates according to where the mouse is pointed but as I said it just rotates infinitely and Im not sure why. Below is the code I have for the player rotation based on mouse position given from the tutorial.
    Plane plrPlane = new Plane(Vector3.up, transform.position);
         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         float hitDist = 0f;
 
         if (plrPlane.Raycast(ray, out hitDist))
         {
             Vector3 targetPoint = ray.GetPoint(hitDist);
             Quaternion targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
             targetRotation.x = 0;
             targetRotation.z = 0;
 
             transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime);
         }
Its pretty straight forward but not understanding what could be causing this issue? Maybe I should change some things in cinemachine? Im not sure.
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                