Hey,
I found a script online making a 2d sprite follow the player. It works but on the y axis as well as the x. I only want the x axis or I’d have a flying zombie. Could someone please tell me how to change this script so it’ll work on the x axis only?
using UnityEngine;
using System.Collections;
public class F : MonoBehaviour {
public Transform target;
public int moveSpeed;
public int rotationSpeed;
public int maxdistance;
private Transform myTransform;
void Awake()
{
myTransform = transform;
}
void Start ()
{
maxdistance = 2;
}
void Update () {
if (Vector3.Distance(target.position, myTransform.position) > maxdistance)
{
// Get a direction vector from us to the target
Vector3 dir = target.position - myTransform.position;
// Normalize it so that it's a unit direction vector
dir.Normalize();
// Move ourselves in that direction
myTransform.position += dir * moveSpeed * Time.deltaTime;
}
}
}