- Home /
A.I. Avoid Light
I have a script that consists of an A.I. using a ray to locate a certain object with a certain tag and avoid that object:
var hit : RaycastHit;
var forward = transform.TransformDirection(Vector3.forward);
if(Physics.Raycast(transform.position,forward,hit, 5)){
if(hit.collider.tag == "Light"){
transform.Rotate(Vector3.up * 10);
}}
My question is, is that this doesn't really work, for the A.I. will continue to head towards the player, so what can be done for the A.I. to actually avoid the light? (I've gotten this idea off of the game, Slender: The Arrival, and I wanted to implement that same process)
Answer by babaji1234 · Jun 21, 2014 at 03:28 PM
try-
var hit : RaycastHit;
var forward = transform.forward;
if(Physics.Raycast(transform.position,forward,hit, 5)){
if(hit.collider.tag == "Light"){
transform.Rotate(Vector3.up * 10);
}}
if that doesn't work then maybe you dont have a collider on the light object
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Coordinating multiple AI enemies 3 Answers
How to make basic AI in a 2d game? 4 Answers
Unity 3D Audio Clip Disabled 1 Answer
Rigidbody AI script needed 0 Answers