for example lets say i want to send 8 rays evenly distributed around a certain position like this:
how would i calculate the direction of each ray?
1 Like
What do you need to use this for?
i want to make a grenade launcher for my game that shoots bullets around the grenade when it hits something
This code here can help you a lot:
local PartShooting = script.Parent -- part that fires rays
local Degrees = -45
for i = 360, -360, Degrees do
local Angle = i
local Rotation = CFrame.Angles(math.rad(Angle), 0,0)
local rayAngle = Ray.new(PartShooting.CFrame.Position, (PartShooting.CFrame * Rotation).lookVector * 20)
local anglePart, position = workspace:FindPartOnRayWithIgnoreList(rayAngle, {PartShooting})
-- Visualize the rays, not necessary, you can delete it
local VisualRay = Instance.new("Part")
local StartPos = rayAngle.Origin
local Endpos = StartPos + (rayAngle.Direction)
local distance = (StartPos - Endpos).Magnitude
VisualRay.Size = Vector3.new(0.3, 0.3, distance)
VisualRay.CFrame = CFrame.new( StartPos , Endpos) * CFrame.new(0, 0, -distance *.5)
VisualRay.Anchored = true
VisualRay.Parent = workspace
end
5 Likes
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.