- Home /
Lerping Camera for character movement.
Hi I started looking at the unity tutorial for mecanim and was wondering how the camera worked. I'm somewhat new to lerping so using it with a camera is somewhat foreign to me. I commented out the if statement and only left the code that refers to Standard Pos so that I only have to focus on the camera following the character at the moment. So in the first line it seems like your changing the transform.position from its current position to whatever position the character moves to, but what is the purpose of the second line. I thought you were already changing the position so whats the purpose of transform.forward.
using UnityEngine;
using System.Collections;
public class ThirdPersonCamera : MonoBehaviour
{
public float smooth = 3f; // a public variable to adjust smoothing of camera motion
Transform standardPos; // the usual position for the camera, specified by a transform in the game
Transform lookAtPos; // the position to move the camera to when using head look
void Start()
{
// initialising references
standardPos = GameObject.Find ("CamPos").transform;
if(GameObject.Find ("LookAtPos"))
lookAtPos = GameObject.Find ("LookAtPos").transform;
}
void FixedUpdate ()
{
/*
// if we hold Alt
if(Input.GetButton("Fire2") && lookAtPos)
{
// lerp the camera position to the look at position, and lerp its forward direction to match
transform.position = Vector3.Lerp(transform.position, lookAtPos.position, Time.deltaTime * smooth);
transform.forward = Vector3.Lerp(transform.forward, lookAtPos.forward, Time.deltaTime * smooth);
}
else
{
*/
// return the camera to standard position and direction
transform.position = Vector3.Lerp(transform.position, standardPos.position, Time.deltaTime * smooth);
transform.forward = Vector3.Lerp(transform.forward, standardPos.forward, Time.deltaTime * smooth);
//}
}
}
Answer by Maerig · May 28, 2014 at 08:26 AM
Like the comment above says, it lerps the direction, or as you could say the rotation.