My 3-part (short!) camera scrips

This provides smooth follow motion, rather than instantaneous, and gentle rotates the arm around so that it’s faceing the same way as Ethan (or whatever target),

You should attach my LookToTarget onto the CAMERA, not the arm. But the other two scripts, SpinAroundAutoSmooth and FollowingTarget, are to be attached to the arm. (The arm is just an otherwise empty gameObject that is parented to the main camera).

LookToTarget – on the camera

using UnityEngine;
using System.Collections;

public class LookToTarget : MonoBehaviour
{

public Transform target;

bool refresh = true;

IEnumerator LookingEverySecond(float t){

  transform.LookAt(target);
  yield return new WaitForSeconds(t);
  refresh = true;
  yield return null;

}

void EarlyUpdate()
{
  if (refresh)
  {
  	StartCoroutine(LookingEverySecond(0.5f));
  	refresh = false;
  }
}

}

FollowingTarget – on the arm (camera rig)

using UnityEngine;

public class FollowingTarget : MonoBehaviour {

public Transform target = null;
public float followSpeed = 1;

Vector3 offset;
Vector3 _movementDirection;

void Start(){
if (target == null) return;
offset = target.position - transform.position;

}

void LateUpdate () {
if (target == null) return;

  _movementDirection = target.position - offset;
  transform.position = Vector3.Lerp(transform.position,
  		                _movementDirection,
                                  followSpeed * Time.deltaTime);

}
}

SpinAroundAutoSmooth – on the cam arm

using UnityEngine;

public class FollowingTarget : MonoBehaviour {

public Transform target = null;
public float followSpeed = 1;

Vector3 offset;
Vector3 _movementDirection;

void Start(){
if (target == null) return;
offset = target.position - transform.position;

}

void LateUpdate () {
if (target == null) return;

  _movementDirection = target.position - offset;
  transform.position = Vector3.Lerp(transform.position,
  				 _movementDirection,
                                 followSpeed * Time.deltaTime);

}
}

Privacy & Terms