The camera needs to follow the object on the Z axis, not the X axis. How do I do this? I usually use C#.
Thank you
The camera needs to follow the object on the Z axis, not the X axis. How do I do this? I usually use C#.
Thank you
using UnityEngine;
using System.Collections;
public class HermeCameraFollow : MonoBehaviour {
// written by herman darr july 20 2014 6:12PM
public Transform playerToFollow;
public Transform farLeft;
public Transform farRight;
void Update () {
if(playerToFollow)
{
Vector3 newPosition = transform.position;
newPosition.z = playerToFollow.position.z;
newPosition.z = Mathf.Clamp(newPosition.z,farLeft.position.z,farRight.position.z);
transform.position = newPosition;
}
}
}
This might work…make 2 empty gameObjects position left and right, where you want them
If your doing this in update, you can possibly keep setting the X and Y axis to 0 at the same time as setting the Z axis towards the object, I am pretty sure it would go like this:
Transform.LookAt(0,0,Target.transform.position.z);
Untested code but that should work.
This is the script I use, Its in Javascript though,
#pragma strict
var Target : Transform;
var distance = 1;
function Update () {
transform.position = Target.position + Vector3( 0,0,distance);
transform.LookAt (Target);
}