In my game I have a camera following the character. Here is the code:
using UnityEngine;
using System.Collections;
public class CameraNavigation : MonoBehaviour {
/// <summary>
/// The targeted game object the camera will follow
/// </summary>
public Transform Target;
/// <summary>
/// The speed of the camera
/// </summary>
private const float pSmoothFollow = 3f;
/// <summary>
/// How far the camera will be from the player
/// </summary>
private Vector3 pOffset;
/// <summary>
/// The Traget Camera position.
/// </summary>
private Vector3 pSetTargetCameraPosition;
/// <summary>
/// Initialize components
/// </summary>
void Start()
{
//Initializing the offset
pOffset = transform.position - Target.position;
}
/// <summary>
/// Update Components
/// </summary>
void FixedUpdate()
{
// Create a postion the camera is aiming for based on the offset from the target.
pSetTargetCameraPosition = Target.position + pOffset;
// Smoothly interpolate between the camera's current position and it's target position.
transform.position = Vector3.Lerp(transform.position, pSetTargetCameraPosition, pSmoothFollow * Time.deltaTime);
transform.RotateAround(Vector3.zero, Vector3.up, 20 * Time.deltaTime);
}
}
The problem is that I want the camera to change its view based on where the character is facing and currently its not doing that. Here is a diagram on what I want it to do:
Can someone help me figure out what I need to change in my script in order to get it working? Many thanks in advance!