I made a spread system for my Shotgun but cant get it to display in the air because it says “CFrame is not a valid member of Vector3”
Ive tried to convert the direction into a Vector3 but I cant think of how to
local Dir = CFrame.new(BulletStart,mousehit) * CFrame.Angles(math.rad(math.random(-spread, spread)),math.rad(math.random(-spread, spread)),0)
local Shoot = workspace:Raycast(BulletStart, Dir.LookVector * range, Params)
if not Shoot then
endpos = BulletStart + Dir * range
else
endpos = Shoot.Position
end
Yes, you can imagine a circle whose surface is perpendicular to the axis represented by the general direction and has a radius of spread. The final destination should be anywhere in that circle. I believe this may work:
-- Function to generate a random vector within a given spread
local function randomSpreadVector(spread)
local randomOffset = Vector3.new(
math.random() * spread - spread/2,
math.random() * spread - spread/2,
math.random() * spread - spread/2
)
return randomOffset
end
-- Calculate the general direction
local generalDirection = mousehit - BulletStart
-- Add a random offset within the specified spread
local randomOffset = randomSpreadVector(spread)
local finalDestination = generalDirection + randomOffset
-- Calculate the unit direction vector
local direction = (finalDestination - BulletStart).Unit