On my player I have the component Animator , Rigidbody , Capsule Collider , Third Person User Control script , Third Person Character script.
On the Main Camera there are two scripts but only one is activated for now : Camera Follow and Mouse Orbit With Zoom :
The Camera Follow script is working fine. The problem is when I'm activating the Mouse Orbit With Zoom script if I move the player with the keys WASD and also rotate orbit the camera with the mouse the player lose focus. He does change his direction according to the mouse rotation but also lost focus :
And also for some reason I can make the camera rotation to be diagonal:
The reason Main Camera is not child of the player is that it's making the camera stuttering and rotating very fast on place. That is why I added the Camera Follow script.
The Camera Follow script :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
public Transform player;
public Vector3 offset;
// Update is called once per frame
void Update()
{
transform.position = player.position + offset;
}
}
The orbit script :
using UnityEngine;
using System.Collections;
[AddComponentMenu("Camera-Control/Mouse Orbit with zoom")]
public class MouseCameraOrbit : MonoBehaviour
{
public Transform target;
public float speed;
private void Update()
{
if (Input.GetMouseButton(0))
{
transform.RotateAround(target.position,
transform.up,
-Input.GetAxis("Mouse X") * speed);
transform.RotateAround(target.transform.position,
transform.right,
-Input.GetAxis("Mouse Y") * speed);
}
}
}
My game is adventure game type and the main goal is to make player movement to be with the keys and also to be able to look around like orbiting with the mouse because only following the player will not show where to go , that is why I'm trying to add orbiting, but the orbiting part is just not working good.