Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Trying to make a shotgun. Raycasting. Manipulating Angles?

Asked by 4 years ago
Edited by royaltoe 4 years ago

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)


0
Please put your code properly in the Code Block Luka_Gaming07 534 — 4y
0
Manipulate how? royaltoe 5144 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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!

Ad

Answer this question