Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

Make NPC travel to waypoint

$
0
0
I've been trying to make an NPC travel through a series of waypoints and stop at the end of an array. I started by making the NPC target a single waypoint and move toward int however, i receive these errors when I run the game: NullReferenceException: Object reference not set to an instance of an object NPCMove.Start () (at Assets/Scripts/AI/NPCMove.cs:19) UnassignedReferenceException: The variable target of 'NPCMove' has not been assigned. You probably need to assign the target variable of the NPCMove script in the inspector. UnityEngine.Transform.get_position () NPCMove.Update () (at Assets/Scripts/AI/NPCMove.cs:24) public class NPCMove : MonoBehaviour { public Transform target; public int moveSpeed; public int rotationSpeed; private Transform myTransform; private Transform stopDistance; void Awake(){ myTransform = transform; } // Use this for initialization void Start () { GameObject go = GameObject.FindGameObjectWithTag("WayPoint"); target = go.transform; } // Update is called once per frame void Update () { Debug.DrawLine(target.position, myTransform.position, Color.black); //look at myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed * Time.deltaTime); //move myTransform.position += myTransform.forward *moveSpeed * Time.deltaTime; } Also, how would I make this use an array.

Viewing all articles
Browse latest Browse all 7934

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>