I need some help with some math. I have three varibales “MinimumAngle” and “MaxmimumAngle” and “NumberOfRaycasts”. The trouble is I want to raycast out 10 times from -45 - MinAngle and 45 MaxAngle but I haven’t a clue on how to do this. I have created an image to help express what I mean.
So from Ray Origin I want it to raycast out 9 times like that in the direction of the look vector but with the offset of MinAngle an MaxAngle. How would I get that even spread?
local MinimumAngle = -45
local MaximumAngle = 45
local NumberOfRaycasts = 9
I am not so good with math so help would be very much appreciated form some more experienced. Thanks.
Since there’s a maximum and minimum angle, why not use a single variable called spreadAngle? You only need one variable and add the negative sign in front if you want to negate the value. The way you think about the maximum and minimum angle is based on that one of the sides is the focus rather than the central line cutting through the “cone” or “triangle”.
o I didn’t see that part. Ok so get the angle between the max and min angle.
local between = MaximumAngle - MinimumAngle
local step = between/(NumberOfRaycasts - 1) -- to make the rays start at min angle
for i = 1, NumberOfRaycasts do
local direction = (part.CFrame * CFrame.Angles(math.rad(MinimumAngle + step * (i-1)),0,0)).LookVector
end
Tried to adjust to some comprehensiveness. This works with symmetrical spreads. And oops.
local Part = workspace.Part
local numberOfRaycasts = 9
local spreadAngle = 45
local totalAngle = spreadAngle * 2
local stepAngle = (totalAngle / (numberOfRaycasts - 1))
for i = 1, numberOfRaycasts do
local raycastAngle = ((i - 1) * stepAngle) - spreadAngle
local ray = workspace:Raycast(Part.Position + Vector3.new(0, 0, Part.Size.Z / 2), ((Part.CFrame * CFrame.Angles(math.rad(raycastAngle), 0, 0)).LookVector * 10, raycastParams)
end
Thanks for the help, but do you know if I can verify that ray 1 is 45 and ray 9 is -45 (or vise versa) using dot product or some other means just to be sure? Also you did not mention OBOE.