- Home /
check angle range
I wondering if there was a way to check raycasting on a range of angles.
in context:
this code is how i am currently checking if my character is colliding with a nearby wall.
distf = transform.TransformDirection (Vector3.forward);
if (Physics.Raycast (transform.position, distf, 2))
{
canmoveforward = false;
}
else
{
canmoveforward = true;
}
what i want to do is check a range of angles (ie 0 - 89 degrees) to see if the path is clear for my character instead of just checking the front back and side.
Answer by syclamoth · Jan 14, 2012 at 03:03 AM
Unfortunately, there's no easy way of 'sweeping' a raycast test, other than just shooting off several individual rays in different directions. It depends on how accurate you want your sweep to be. I would write some kind of function that returns an array of RaycastHits, given an angle, a centre direction, a normal and an integer determining how many rays should be cast.
Your answer
Follow this Question
Related Questions
Get angle to retarget collision object. 1 Answer
Slow down object about to collide 1 Answer
Colliders 2d apparently touch each other even if they should not. 2 Answers
spawning on collision 1 Answer