I’m using the very simple script below to move a cone object to a target location when the player touches a trigger. For some reason the cone flies towards the target and then continues on indefinitely and I can’t figure out why. The target and trigger are parented to the the cone object, if that is relevant.
public class ConeObstacle : MonoBehaviour {
public Transform cone;
public Transform target;
private bool active = false;
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Player")){
active = true;
}
}
private void FixedUpdate()
{
if (active) {
cone.position = Vector3.MoveTowards(cone.position, target.position, 50 * Time.deltaTime);
}
}
}