- Home /
Question by
rubenalex367 · May 14, 2018 at 09:21 AM ·
unity 5rotationraycastraycasthit
Multiple raycasts from game object
I got a little scene in unity with obstacles and such where the AI shoots off a raycast to detect if there is wall infront of it, and after that it decides to rotate if such a matter occurs. I am now trying to get multiple raycasts so it can check the same but with the +45 and - 45 angle of vision, otherwise the robot can only check its front ray. How would i do this? Code sample below.
ray = new Ray(transform.position + Vector3.up, transform.forward);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 55f))
{
if (hit.collider.tag == ("Pick Up"))
{
Debug.DrawLine(ray.origin, hit.point, Color.red);
transform.position = Vector3.MoveTowards(transform.position, hit.point, Time.deltaTime * speed);
}
else
{
Debug.DrawLine(ray.origin, hit.point, Color.blue);
transform.Rotate(0, -80 * Time.deltaTime, 0);
}
}
else
{
transform.position += transform.forward * speed * Time.deltaTime;
Debug.DrawLine(ray.origin, hit.point, Color.white);
}
Comment