Ai scripting question

Unfortunately I am not entirely familiar with the javascript language or even C# for that matter but am working on a project and hoped someone might be able to point me in the right direction. I have programmed a rudimentary AI (it moves on its own :stuck_out_tongue: ) it is a patrolling AI which I like for it’s simplicity but I wanted to add some randomness to it by having it perform some “random” pre-defined action in between each of the waypoints in it’s patrole. I figured I could do this with a zone that the AI passes through triggering one of a few events I would have listed in the script somewhere. My trouble is that I do not know the code (working in the unity javascript) that would identify that the AI character is inside the zone. I have placed boxes in the path of my AI and turned off the mesh render so you can’t see them, and for ease of namming all the zones are named “Zone” since there is no reason to differenciate between them. Any help with this would be great, I apologize if this was not the right place to post. And if I need to clarify what I am asking I am more than happy to do so (it’s been a long day so I am not sure I am making sense anymore :stuck_out_tongue: )

Thanks in advance.

It sounds like you need OnTriggerEnter.

ok…so…that sounds incredibly easy…so…of course that can’t be the answer :stuck_out_tongue: …just kidding I am sure thats what I need…I would need to check mark the is trigger box for the cube collider tho correct?

That is correct.

Yes, you need to check the isTrigger box.

Then in your AI script, add the OnTriggerEnter method like in the link Dman gave you. On the link they’re writing it from the perspective of the trigger cube, so in that case “other” points to the thing that just entered the cube. But in your case you probably want to put OnTriggerEnter on your AI, then “other” will point to the cube it just walked into. So you can do something like “if other.Name == “RedCube” TurnLeft() else if other.Name == “BlueCube” TurnRight()”

perfect thanks makeshiftwings (took me like 2 min to write your name correctly…god im tired :stuck_out_tongue: ) I was just about to post to ask the question you answered :stuck_out_tongue: