- Home /
What is wrong with this code? (Solved)
Hi, I have a code, it has no errors, but does not function how i hoped, i want to so when the player is at the waypoint from an array, it targets the next one,
Here is the code
@script RequireComponent(NavMeshAgent);
@script AddComponentMenu("NavMesh/BasicMover");
private var Agent : NavMeshAgent;
var Target : Transform[];
var CurrentTarget = 0;
function Start () {
Agent = gameObject.GetComponent(NavMeshAgent);
}
function Update () {
Agent.SetDestination(Target[CurrentTarget].position);
if(transform.position == Target[CurrentTarget].position)
CurrentTarget++;
}
Thanks ;)
maybe add
Target[CurrentTarget].y=transform.position.y;
What exactly isnt working properly?
You are requiring the player get exactly to a position. Perhaps you should have a check within a distance squared of that position rather than check for actually arriving at the literal target destination?
thanks, wow that was quick, anyway thanks for the help, i did if the x and z are the same and it works fine, so thanks ;)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
My script doesnt respond what i wrote HELP!!! 0 Answers
How can i get ONLY the childrens of a GameOnbject with GetComponentsInChildren method? 5 Answers
Instantiate rigidbody, transform or gameobject? 1 Answer
I want to move a cube with rotation but I find this problem 1 Answer