Oh now you mention shotgun spray? Shouldn’t you have mentioned that in post 1?
So you are doing a raycast shotgun spray from a parts position towards the origin at (0,0,0)?
Then the problem is that the random vector offsetting method is problematic the further away the target position is which seems to be origin if you do -StartPosition. This is further explained below:
Here is another method if you want to keep the vector offset method but standardize the distance problem:
I believe I’ve had enough for today hope this helps.
local part = script.Parent.red
local Params = RaycastParams.new()
Params.FilterType = Enum.RaycastFilterType.Whitelist
Params.IgnoreWater = true
Params.FilterDescendantsInstances = {workspace}
local PhysicsService = game:GetService("PhysicsService")
PhysicsService:CreateCollisionGroup("NonCollide")
PhysicsService:CollisionGroupSetCollidable("NonCollide","Default",false)
local function createTracer(startpos)
local RayDirection = -startpos + Vector3.new(math.random(-30, 30), math.random(-30,30), math.random(-30, 30))
local result = workspace:Raycast(startpos, RayDirection,Params)
if result then
local endpos = result.Position
local distance = (startpos - endpos).Magnitude
local tracer = Instance.new("Part")
tracer.Color = Color3.fromRGB(163, 162, 165)
PhysicsService:SetPartCollisionGroup(tracer,"NonCollide")
tracer.Material = Enum.Material.Neon
tracer.CanQuery = false -- prevent raycasting hitting this
tracer.Anchored = true
tracer.CanCollide = false
tracer.Size = Vector3.new(0.5, 0.5, distance)
tracer.CFrame = CFrame.new(startpos , endpos) * CFrame.new(0, 0, -distance/2)
tracer.Parent = workspace
spawn(function()
for i = 1, 100 do
tracer.Transparency = tracer.Transparency + 0.01
wait(0.01)
end
tracer:Destroy()
end)
end
end
for i = 1, 100 do
createTracer(part.Position)
wait(0.05)
end
These produced the results I wanted. Literally all I had to do there I think was change “local hit = result.Instance” to “local endpos = result.Position” The parts visualizing the rays now stop directly at the surface of the baseplate, which was what I wanted. Thank you everyone for helping.
That was one of my first projects: Shrapnel graphics and all. Close enough and you can blow the limbs off players, but won’t kill you, unless it blows off Head.
But Filtering broke it, and it’s just a bunch of fudge.