Currently, I am trying to make an enemy go from point A to point B smoothly with triggers. I’m using lerp but it is not working. The enemy will snap to point B instead of smoothly going to it. Any suggestions? Here’s the code:
public GameObject enemyAI;
public GameObject sensor;
private Vector3 point;
public float speed = 1.0f;
private float step;
private bool sensorCheck = false;
// Use this for initialization
void Start ()
{
point = sensor.transform.position;
}
// Update is called once per frame
void Update ()
{
step = speed * Time.deltaTime;
if (sensorCheck == true)
{
enemyAI.transform.position = Vector3.Lerp(transform.position, point, step);
}
}
void OnTriggerEnter(Collider other)
{
sensorCheck = true;
}
void OnTriggerExit(Collider other)
{
sensorCheck = false;
}