How To Make The Camera turn around the player using the mouse only separatly from character movement?
Hi Im not very good at c# but good at unity anyway i was making a game like gta v and i start with making the camera first and i have success with that . second thing i have start making is the movement and for the vertical movement it was good but when came to make the horizontal movement it worked too but the problem is when i move left and right the camera are turning left and right using ("a" button And "d" btton) that's mean when ever i move the player left and right the camera is turning left and right too using these two button But this is not what i want . for butter understanding please whatch this video to see the problem https://youtu.be/5ZPQg8EjIJ0 . Now here is what i did
1- first i made an empty game object that has two things the player prefab and the camera as the child Notice: i didnt make the camera a child of the player prefab
2- i made the cameraTurn Script And add it to the main camera
Here is the cameraTurn Script
using UnityEngine; using System.Collections;
public class cameraTurn : MonoBehaviour {
[SerializeField] private Transform target;
public float rotSpeed = 1.5f;
private float _rotY;
private Vector3 _offset;
void Start()
{
_rotY = transform.eulerAngles.y;
_offset = target.position - transform.position;
}
void LateUpdate()
{
float horInput = Input.GetAxis("Horizontal");
if (horInput != 0) {
_rotY += horInput * rotSpeed;
} else {
_rotY += Input.GetAxis("Mouse X") * rotSpeed * 3;
}
Quaternion rotation = Quaternion.Euler(0, _rotY, 0);
transform.position = target.position - (rotation * _offset);
transform.LookAt(target);
}
}
3- I have made an small sphere and add it to the player prefab as a child and made at the top of the character and call it Mind
And Then i have added the mind as a target for the camera so the camera can look at it when ever it turning
Now if you start the game and move your mouse left and right you can see the camera are looking on the player while it move like gta v and also if you pressed [a] key and [d] key the camera will go around too and this is not what i want because if i keep going and making the movement it will be disaster just like the video you have seen in the top
Hope its all good And if there anything feel free to comment and i will give you more info Thanks,
Your answer
Follow this Question
Related Questions
I can't make transition from actual animation to previous one 1 Answer
Where can I learn C# 3 Answers
how to make forward relative to the view of the camera 0 Answers
How to Lock Steam VR camera to the head of the Player model 0 Answers
Camera isn't move position? Why my camera isn't change position? 0 Answers