- Home /
how to detect if transform.lookat is going through walls?
Hi, im trying to set up my own way point AI for a tag style game. currently i only have dumb ai that goes straight to the target. so if the target goes upstairs, the NPC doesnt know how to get to it.
i have set up some waypoints (how i think will work), but i dont know how to set up the condition for it to start using the waypoints. the best way i can think of is if the line between the NPC and the target has a collider in it, and if so choose the best path to the target.
so my question would be is there like some kind of boolean to know if there is a colider between the ai using transform.lookat and its target?
Answer by Julien-Lynge · Sep 29, 2011 at 05:01 AM
What you need to look into is Raycasting. You can turn your transform.lookat vector into a ray pretty easily and use Physics.Raycast to determine if the ray intersects any colliders.
Good luck.
BTW, to avoid confusion I didn't mean to imply that you could change transform.lookat into a ray directly, but rather create a ray in its place with something like targetTransform.position - transform.position.