- Home /
The question is answered, right answer was accepted
[C#] Raycasts and Object Tags
I have this code that cast three rays in font of an ai to check if there if something there. then if something is there.
Physics.Raycast(transform.position, left, out lhit, StayD);
Physics.Raycast(transform.position, fwd, out hit, StayD);
Physics.Raycast(transform.position, right, out rhit, StayD);
if(hit.collider.tag == CTag && lhit.collider.tag == CTag && rhit.collider.tag == CTag)
transform.Translate(Vector3.forward * Time.deltaTime * MoveSpeed);
this code was intended to make the ai move forward if the object in front of it has the same tag as the string CTag, and not move if any other object is infront of it, and move when there is nothing infront of it. i am not sure of how to do this, can any one help me.
Not enough information. What is the problem that you are experiencing, specifically?
"move when there is nothing infront of it"
But your IF statement doesn't include a conditional to call transform.Translate when no hits are detected. Do you handle this elsewhere? Is this the problem you're experiencing?
I was trying to make the rag ignore a specific object without putting it on the ignore raycast layer, I was able to accomplish this by using a layer mask, after looking at the documentation for raycasts
Answer by TheDarkVoid · Jul 05, 2012 at 01:21 PM
i resolved managed to solve my problem by using a layer mask. http://docs.unity3d.com/Documentation/Components/Layers.html scroll down to casting raycasts selectively.
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Best way to do an AI 1 Answer
AI Pathfinding using RayCast 0 Answers
Another Raycast Issue. 0 Answers
2D Field of View 2 Answers