Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Trying to make a shotgun. Raycasting. Manipulating Angles?

Basically. Im trying to make a shotgun with raycasting but I have no idea how to manipulate the angles.

game.ReplicatedStorage.RayCast.OnServerEvent:Connect(function(player,exit,mousehit)
	local ray = Ray.new(exit.Position, (mousehit.Position - exit.CFrame.Position).unit * 500)
	local part,position = workspace:FindPartOnRay(ray,player,false,false)
	local bullet = Instance.new("Part",workspace)
	bullet.Material = Enum.Material.Neon
	bullet.BrickColor = BrickColor.new("Bright yellow")
	bullet.CanCollide = false
	bullet.Anchored = true
	bullet.Locked = true
	local distance = (exit.Position - position).magnitude
	bullet.Size = Vector3.new(-8.855, 0.025,distance)
	bullet.CFrame = CFrame.new(exit.Position, position) * CFrame.new(0,0,-distance / 2)
	game:GetService("Debris"):AddItem(bullet, .1)
end)


2 comments

0

Please put your code properly in the Code Block

0

Manipulate how?

1 answer

Hello friend!

I also came across this issue too. It's very annoying.

Perhaps making a part that is like this:

local aimPart = Instance.new("Part")
aimPart.Position = tool.Handle
aimPart.Anchored = true
aimPart.Transparency = 1
aimPart.Size = Vector3.new(1,1,1)
aimPart.Parent = workspace
aimPart.CFrame = aimPart.CFrame * CFrame.Angles(math.rad(math.random(-1,1)),0,math.rad(math.random(-1,1)))
bullet.CFrame = CFrame.new(bullet.Position, aimPart.Position)

Could make the effect of a 'spread'. I'm not entirely sure if the raycast will actually detect it, but this is the closest answer I can think of.

P.S, change the math.random() with the negative degree of spread, and the positive degree of spread.

Happy coding Expertsm!

This discussion is preserved as it was. New answers, comments, and votes are closed.