I'm making a game where you have a friend follow you. I have a script that partly works, but when the friend exits the trigger, it won't follow the player.
How do I get the friend to follow the player once indefinitely, or until it hits the trigger again?
Here is the script:
public Transform friend;
private int movespeed;
public int speed;
public Rigidbody rb;
// Use this for initialization
void Start()
{
speedup();
}
// Update is called once per frame
void Update()
{
transform.LookAt(freind);
Vector3 eulerAngles = transform.rotation.eulerAngles;
eulerAngles.x = 0;
eulerAngles.z = 0;
transform.rotation = Quaternion.Euler(eulerAngles);
rb.AddRelativeForce(0, 0, movespeed);
}
public void OnTriggerStay(Collider other)
{
if (other.tag == "Player")
{
movespeed = 0;
}
else
{
speedup();
}
}
public void speedup()
{
movespeed = speed;
}