So I wrote this simple AI script for an airplane to move between waypoints, and wrote my thinking in the comments. However, after the plane destroys the 1st waypoint, it moves partially into the direction of the 2nd waypoint, but never hits the 2nd waypoint. So while it is moving slightly into the right direction… it never actually hits Waypoint2. What am I doing wrong? THANK YOU SO MUCH!
using UnityEngine;
using System.Collections;
public class AICustomScript : MonoBehaviour
{
//first waypoint
public Transform Waypoint;
//second waypoint
public Transform Waypoint2;
void Start()
{
rb = GetComponent<Rigidbody>();
//make plane point in direction of first waypoint
transform.LookAt(Waypoint);
}
//allow me to select amount of force in editor
public float AddForceAmount;
//allow me to select plane in editor
public Rigidbody rb;
/void FixedUpdate()
{
//make plane move
rb.AddForce(transform.forward * AddForceAmount);
}
//PART OF CODE TO DETECT ARRIVAL ON WAYPOINT
void OnTriggerEnter(Collider other)
{
if (other.gameObject)
{
//destroys waypoint
Destroy(other.gameObject);
//makes plane look at 2nd waypoint (Waypoint2)
transform.LookAt(Waypoint2);
}
}
}
//SO WHAT'S WRONG?