|
I have looked around at least three days now and I can't seem to find anything about incorporating a disable script along side a waypoint script. Essentially I want the AI to become disabled as soon as it has finished its last waypoint. How would I begin to do this? Below is the script. SCRIPT EDIT-> I have changed the original script to support the ones the people who have answered my question. Thanks! var waypoint : Transform; var speed : float = 20; var distanceToTarget : float = Vector3.Distance(transform.position, EvilCube); function Update() { var target : Vector3 = waypoint.position; var moveDirection : Vector3 = target - transform.position; var velocity = rigidbody.velocity; if(moveDirection.magnitude < 1){
} else{
}
}
(comments are locked)
|
|
calculate the distance between this object and the waypoint position (in your script, "target"), using Vector3.Distance:
Then check if the distance is zero, which would mean you reached the target, and disable the gameobject: That would be a better way.
Jan 03 '11 at 07:15 PM
NinjaSquirrel
Okay I will try all of your ideas. Thanks for the prompt replies, I appreciate it immensely.
Jan 03 '11 at 07:34 PM
Didymos
Is this the right way then? Script listed below var waypoint : Transform; var speed : float = 20; var distanceToTarget : float = Vector3.Distance(transform.position, EvilCube); function Update() { var target : Vector3 = waypoint.position; var moveDirection : Vector3 = target - transform.position; var velocity = rigidbody.velocity; if(moveDirection.magnitude < 1){ velocity = Vector3.zero; if(distanceToTarget == 0) } else{ } }
Jan 03 '11 at 08:34 PM
Didymos
I edited my question and changed the original script I had posted I posted a new script with the suggestion that you have advised me. Did I do it correctly?
Jan 03 '11 at 08:43 PM
Didymos
Your script works all except the first part "var distanceToTarget : float = Vector3.Distance(transform.position, target);" I found that if I simply put ""var distanceToTarget : float" that the object is disabled. +1 and best answer.
Jan 03 '11 at 09:33 PM
Didymos
(comments are locked)
|
|
I would put a variable in there and name it "waypointReached", make it a boolean. start of with it's boolean false, then once it has reaches the waypoint change it to true. then add code, where if waypointReached is true, destroy the object. Hope that helps some. Thanks, I will try that.
Jan 03 '11 at 07:11 PM
Didymos
No problem. :)
Jan 03 '11 at 07:12 PM
NinjaSquirrel
(comments are locked)
|

Do you only have one waypoint, or an array of waypoints?
I have just one waypoint currently. I am simply just trying to disable the GameObject once it reaches the waypoint.
Disable the GameObject, or just this script?
Well I simply want to disable the GameObject once it is done with the waypoint.