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

Which bodyforce is best for Bullets, Flying balls, etc?

Asked by
joalars2 107
8 years ago

Just wondering. Making a staff which shoots a ball of magical DEATH.

0
Bodythrust. drahsid5 250 — 8y
0
Does bodythrust send it flying a specific vector? joalars2 107 — 8y
0
bodythrust sends it in the specified direction relevant to the part. you're better off with bodyvelocity aquathorn321 858 — 8y
0
Ah, thanks. Wouldnt wanna be forced to rotate the ball every time, lol. joalars2 107 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

Your best bet is probably going to be BodyVelocity. BodyVelocity sends the object at a certain speed in a certain direction. These are both determined in the same value "Velocity", which is sort of like the slope in three dimensions. This is the best choice, unless you want them to be homing missiles or include acceleration.

Here's an example of how to create your missile:

--local script in StarterGui

local player = game.Players.LocalPlayer --define the player
local character = player.Character --define the character
local mouse = player:GetMouse() --define the player's mouse

local missile = Instance.new("Part") --define our missile
missile.Shape = 0
missile.BrickColor = BrickColor.new("Dark indigo")
missile.Transparency = .5
missile.Size = Vector3.new(1,1,1)
missile.TopSurface = "Smooth"
missile.BottomSurface = "Smooth"
local f = Instance.new("Fire",missile)--add fire trail
f.Color = Color3.new(1,0,1)
f.SecondaryColor = Color3.new(1,0,1)

mouse.Button1Down:connect(function()--fire function when player clicks mouse
    local start = character.Head.Position + Vector3.new(0,3,0) --where we want the missile to start at, 3 studs above the player's head
    local target = mouse.Hit.p --the location the mouse is pointing at
    local clone = missile:Clone() --clone the missile
    local bv = Instance.new("BodyVelocity",clone) --create our body velocity
    bv.Velocity = (target - start).unit*50 --change the velocity value
    --(target - start).unit is the direction we want to fire the missile at, and *50 is the speed we want it to travel at.

    clone.Touched:connect(function(hit)--fire function when missile is touched
        if hit:IsDescendantOf(character) then--fire given code if touched part is a descendant of the character who fired the missile
            return--terminate code
        end
        local b = Instance.new("Explosion")--create explosion
        b.Position = clone.Position--position explosion at missile
        b.Parent = workspace--put explosion in workspace
        clone:Destroy()--destroy missile
    end)

    clone.CFrame = CFrame.new(start,target)*CFrame.Angles(math.rad(90),0,0) --Positions the missile above the player. We don't have to rotate it, but it prevents the fire from looking odd as the missile travels.
    clone.Parent = workspace --put missile in the workspace
    wait(10)--yield code for 10 seconds
    if clone then--if missile still exists then fire given code
        local b = Instance.new("Explosion")--create explosion
        b.Position = clone.Position--position explosion at missile
        b.Parent = workspace--put explosion in workspace
        clone:Destroy()--destroy missile
    end
end)
0
I made you an example you could look to if you were having trouble aquathorn321 858 — 8y
Ad

Answer this question