So im making shotgun and i want to calculate final posiiton of bullet (see script) but it act weirdly
Problem:
its counting the unit from position 0,0,0 and i want it around player, here is code:
script.Parent.Shoot.OnServerEvent:Connect(function(player, pos, origin)
for i = 0,8,1 do
local distanceShoot = (pos - origin).magnitude
local SpreadPos = pos + Vector3.new(math.random(0 - distanceShoot,distanceShoot)/30,math.random(0 - distanceShoot,distanceShoot)/30,math.random(0 - distanceShoot,distanceShoot)/30)
local Bullet = game.ReplicatedStorage.Bullet:Clone()
Bullet.Parent = game.Workspace.GunShoots
Bullet.Anchored = true
local direction = (SpreadPos - origin).Unit*50
print(SpreadPos)
local result = workspace:Raycast(origin, direction)
Bullet.Position = direction
end
end)
script is server based, pos is mouse position, origin is gun position, the script is not complete