- Home /
 
               Question by 
               Chocolade · May 11, 2017 at 05:43 PM · 
                c#scripting problemscript.  
              
 
              How can i rotate the camera with the mouse around the player ?
Now when i move the mouse around it's rotating the camera but when the player is walking and i rotate the camera it will not follow the player i can rotate anywhere.
What i want to to now is to change it so when i move the mouse around it will rotate the camera around the player when he walk or idle so i can look the player face or back look up down but always around the player.
 using UnityEngine;
 using System.Collections;
 
 public class CameraMover : MonoBehaviour
 {
     public float speedH = 2.0f;
     public float speedV = 2.0f;
     private float yaw = 0.0f;
     private float pitch = 0.0f;
 
     public Transform playerTransform;
     public Transform mainCameraTransform = null;
     private Vector3 cameraOffset = Vector3.zero;
     public float turnSpeed = 3;
 
     void Start()
     {
         mainCameraTransform = Camera.main.transform;
         //Get camera-player Transform Offset that will be used to move the camera 
         cameraOffset = mainCameraTransform.position - playerTransform.position;
     }
 
     void LateUpdate()
     {
         //Move the camera to the position of the playerTransform with the offset that was saved in the begining
         mainCameraTransform.position = playerTransform.position + cameraOffset;
 
         yaw += speedH * Input.GetAxis("Mouse X");
         pitch -= speedV * Input.GetAxis("Mouse Y");
         mainCameraTransform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
     }
 }
 
I tried to add after the line with the eulerAngles a line with LookAt:
 mainCameraTransform.LookAt(playerTransform.position);
But then the rotation with the mouse is not working at all.
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                