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

Is there a good way to add spread to my spell?

Asked by 6 years ago
Edited 6 years ago

this attack/spell is a shotgun-esk attack in which a barrage of 6 bullets hits an enemy. But it doesn't spread like a normal shotgun. Is there a good way to add spread to my spell?

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Mouse = Player:GetMouse()
Enabled = true

Mouse.KeyDown:connect(function(key)
    if Enabled == false then return end
    key = key:lower()
    if key == 'r' then
        Enabled = false

        for i=1,6 do
        --Fire Ball Projectile
        local FireBall = Instance.new('Part')
        FireBall.Shape = 'Ball'
        FireBall.Name = "FireBall"
        FireBall.Material = 'Neon'
        FireBall.BrickColor = BrickColor.new('Dark orange')
        FireBall.Parent = Character.ProjectileStorage
        FireBall.CFrame = Character.Torso.CFrame*CFrame.new(0,0,-1.5)
        FireBall.Size = Vector3.new(1,1,1)
        FireBall.Transparency = 0.1
        FireBall.CanCollide = false

        --Sound Effects
        local Fire2 = script:WaitForChild('Fire2')

        local BV = Instance.new('BodyVelocity')
        BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
        BV.Velocity = Character.Torso.CFrame.lookVector*50
        BV.Parent = FireBall
        local Dmg = script:WaitForChild('FireDamage'):Clone()
        Dmg.Parent = FireBall
        Dmg.Disabled = false

        Fire2:play()

        --Particles
        local FireParticle1 = script:WaitForChild('ParticleEmitter'):Clone()
        FireParticle1.Parent = FireBall

        FireBall:clone()

        wait(0.1)

        --FireBall Destroy
        local Disapper = script:WaitForChild("Disappear"):Clone()
        Disapper.Parent = FireBall
        Disapper.Disabled = false

        end

        wait(3)
        Enabled = true
    end
end)
0
I also used a for loop, so whoever got upset at me, are you happy now? KatsuneSniper 31 — 6y
0
Thats not what I meant. hiimgoodpack 2009 — 6y
0
keybaord input of that method is deprecated use this : http://wiki.roblox.com/index.php?title=Keyboard_input abnotaddable 920 — 6y
0
add random rotation to them abnotaddable 920 — 6y

1 answer

Log in to vote
2
Answered by
gskw 1046 Moderation Voter
6 years ago
Edited 6 years ago

You would want to add a random factor to the velocity:

local spread = 5 -- Try changing this to suit your needs
BV.Velocity = Character.Torso.CFrame.lookVector*50 + Vector3.new(
    spread*math.random()*2 - spread,
    spread*math.random()*2 - spread,
    spread*math.random()*2 - spread)
-- Adds -5 to 5 units of velocity on each axis randomly

Also, make sure you initialize your randomizer with proper entropy by placing this at the start or end of the script:

math.randomseed(tick())
0
YEa NerdBow_Gaming 41 — 6y
0
thanks KatsuneSniper 31 — 6y
0
I have improved my answer since you last commented. The code now allows the random spread number to be any number in the range instead of just whole numbers. gskw 1046 — 6y
Ad

Answer this question