I’m improving my web swing for my game and it doesn’t attach to the buildings properly,
some of them are left floating in the air. How can I shoot multiple raycasts around me so I can detect the ideal position of the origin point
You could have a for-loop iterate from 0 to 2*pi, on some unit of radians as an interval, and use that to determine an angle from the players’ RootPart, hand, whatever the origin is, along the y-axis. From there you could raycast at whatever x/z angle you need to. Loop until you find a building to attach to, and if the loop finishes without the ray hitting anything, don’t shoot a web.
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HRP = Character:WaitForChild("HumanoidRootPart")
local Mouse = Player:GetMouse()
local RaycastParameters = RaycastParams.new()
RaycastParameters.FilterDescendantsInstances = Character
RaycastParameters.FilterType = Enum.FilterType.Blacklist
RaycastParameters.IgnoreWater = true
local function CastRays()
local Origin = HRP.Position
local Target = Mouse.Hit.Position
local Unit = (Target - Origin).Unit
local Direction = Unit * 1000
local RaycastResults = {}
for Angle = 0, 360, 22.5 do
local RaycastResult = workspace:Raycast(Origin, (CFrame.new(Direction) * CFrame.Angles(0, math.rad(Angle), 0)).Position, RaycastParameters)
if RaycastResult then
table.insert(RaycastResults, RaycastResult)
end
end
return RaycastResults
end
local RaycastResults = Mouse.Button1Click:Connect(CastRays)