Angles in raycast

  1. What do you want to achieve? Keep it simple and clear!
    I want to make an turret that checks 180 degrees if there is an humanoid there within 10 studs range with raycast

  2. What is the issue? Include screenshots / videos if possible!
    i cannot get it working

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    i tried to look at some devforum topics

1 Like

You would just need to fire multiple raycasts in a semi-circle to check the 180 degrees. (unless there is an easier way that came around more recently. I’ve been on here for awhile and a lot of things changes)

1 Like

You could loop through every humanoid in the workspace then check if they are within 10 studs of the turret then use dot product to figure out if it’s within the disired angle

2 Likes

This is very inefficient in my opinion. Shooting that much ray in such little interval would be quite expensive

1 Like

What do you mean by dot product i’ve never heard it before

1 Like

I’m not the best at explaining but this video might help:

3 Likes

This is perfectly what i need thank you :smiley:

2 Likes

You’re right, I’m tired after just coming off a 12 hour security shift, and I haven’t done raycasting in awhile as I’ve been mostly doing UI and websites recently.

2 Likes

Fun fact, you can also get the angle between two vectors by doing this:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.