- Home /
just need it to follow on y
Code is working great...but is there any simple way I can make it follow just on the y axis? Any help would be great since I am bad with code. Thank you in advance. :)
using UnityEngine;
using System.Collections;
public class SmoothFollow2 : MonoBehaviour {
public Transform target;
public float distance = 3.0f;
public float height = 3.0f;
public float damping = 5.0f;
public bool smoothRotation = true;
public bool followBehind = true;
public float rotationDamping = 10.0f;
void Update () {
Vector3 wantedPosition;
if(followBehind)
wantedPosition = target.TransformPoint(0, height, -distance);
else
wantedPosition = target.TransformPoint(0, height, distance);
transform.position = Vector3.Lerp (transform.position, wantedPosition, Time.deltaTime * damping);
if (smoothRotation) {
Quaternion wantedRotation = Quaternion.LookRotation(target.position - transform.position, target.up);
transform.rotation = Quaternion.Slerp (transform.rotation, wantedRotation, Time.deltaTime * rotationDamping);
}
else transform.LookAt (target, target.up);
}
}
Comment
Best Answer
Answer by Kiwasi · Jul 05, 2014 at 08:09 PM
Simply set your x and z to their current position.
wantedPosition = target.TransformPoint(transform.position.x, height, transform.position.z);
Your answer
Follow this Question
Related Questions
Camera follow smoothness problem 1 Answer
camera follow an game object 0 Answers
2d camera follow player by looking ahead. 1 Answer
Camera Border Follow 1 Answer