hi guys trying to get the distance between one objetc and the leader, and make it follow the leader but have a set “GAP” between them, trying to find the distance and ajust it to the set GAP so my objects following the leader are evenly spaced out like in space shooters.
using UnityEngine;
using System.Collections;
public class Follow : MonoBehaviour {
public Transform Leader;
public float GAP = 10;
public float speed = 10;
public float GapSmooth = 5f;
// Use this for initialization
void Start () {
// get distance:
float dist = Vector3.Distance(Leader.position, transform.position);
}
// Update is called once per frame
void Update () {
transform.LookAt (Leader);
transform.Translate(Vector3.forward * speed * Time.deltaTime);
// GAP:
if(dist < GAP && dist > GAP){dist = GAP * GapSmooth *Time.deltaTime;}
}
}