I am very new to unity and everything I have done in my game so far has been done by following tutorials on YouTube but now I am at a point to where tutorials are not telling me what I need to know so I feel like it is time that I turn to the forums for answers. Anyhoo, I have this code for my third person camera and it works great but my problem is I do not know what I need to add to this code to get my player to move in the direction that the camera is facing. say for example I move my mouse to the left I want the player to rotate with the mouse and follow the camera to the left and if I move my mouse to the right I want the player to rotate with the mouse and follow the camera to the right.
This is the code I have so far.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ThirdPersonCamera : MonoBehaviour
{
public float MouseSensitivity = 10;
public Transform Target;
public float DistanceFromTarget = 2;
public Vector2 PitchMinMax = new Vector2(-40, 85);
public float RotationSmoothTime = .12f;
Vector3 RotationSmoothVelocity;
Vector3 CurrentRotation;
public Transform Pivot;
float yaw;
float pitch;
void LateUpdate()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
yaw += Input.GetAxis("Mouse X") * MouseSensitivity;
pitch -= Input.GetAxis("Mouse Y") * MouseSensitivity;
pitch = Mathf.Clamp(pitch, PitchMinMax.x, PitchMinMax.y);
CurrentRotation = Vector3.SmoothDamp(CurrentRotation, new Vector3(pitch, yaw), ref RotationSmoothVelocity, RotationSmoothTime);
transform.eulerAngles = CurrentRotation;
transform.position = Target.position - (transform.forward * DistanceFromTarget);
}
}
If you can tell me what I should add to this code and how I would implement it into the code so it functions properly I would greatly appreciate it. Thanks in advance.