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

How can I make my bullet travel in a straight line without it being effected by gravity?

Asked by
faruque 30
9 years ago
local Tool = script.Parent;

enabled = true

local spark = Instance.new("Sparkles")
spark.Color = Color3.new("Really red")

function fire(v)

    local vCharacter = Tool.Parent
    local vPlayer = game.Players:playerFromCharacter(vCharacter)

    local missile = Instance.new("Part")


    spark:Clone().Parent = missile

    local spawnPos = vCharacter.PrimaryPart.Position

    local PewPew = Tool.Handle:FindFirstChild("PewPew")

    if (PewPew == nil) then
        PewPew = Instance.new("Sound")
        PewPew.Name = "PewPew"
        PewPew.SoundId = "http://www.roblox.com/asset/?id=88633606"
        PewPew.Parent = Tool.Handle
        PewPew.Volume = 1
    end


    spawnPos  = spawnPos + (v * 6)


    missile.Position = spawnPos
    missile.FormFactor = "Custom"
    missile.Size = Vector3.new(2.5,0.2,0.2)
    missile.Velocity = v * 90
    missile.BrickColor = BrickColor.new("Really red")
    missile.BottomSurface = "Smooth"
    missile.TopSurface = "Smooth"
    missile.Name = "Spark"
    missile.Reflectance = 0
    missile.CanCollide = false 

    local force = Instance.new("BodyForce")
    force.force = Vector3.new(0,98,0)
    force.Parent = missile


    local creator_tag = Instance.new("ObjectValue")
    creator_tag.Value = vPlayer
    creator_tag.Name = "creator"
    creator_tag.Parent = missile

    local new_script = script.Parent.LaserBlast:clone()
    new_script.Disabled = false
    new_script.Parent = missile

    missile.Parent = game.Workspace

    PewPew:Play()

end



function gunUp()
    Tool.GripForward = Vector3.new(0, 0, -1)
    Tool.GripRight = Vector3.new(1, 0, 0)
    Tool.GripUp = Vector3.new(0, 1, 0)
end

function gunOut()
    Tool.GripForward = Vector3.new(0, 0, -1)
    Tool.GripRight = Vector3.new(1, 0, 0)
    Tool.GripUp = Vector3.new(0, 1, 0)
end

function isTurbo(character)
    return character:FindFirstChild("BoltHelm") ~= nil
end


function onActivated()
    if not enabled  then
        return
    end

    enabled = false


    local character = Tool.Parent;
    local humanoid = character.Humanoid
    if humanoid == nil then
        print("Humanoid not found")
        return 
    end

    local targetPos = humanoid.TargetPoint
    local lookAt = (targetPos - character.Head.Position).unit

    local reload = .1
    --if (isTurbo(character)) then
    --  reload = .25
    --  print("turbo")
    --end

    gunUp()
    fire(lookAt)
    wait(reload)
    gunOut()
    wait(reload)

    enabled = true

end

function onEquipped()
    Tool.Handle.EquipSound:play()
end

script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)

1
Add a BodyGyro. I suggest looking up how to use it on the Wiki, it stabilizes bricks. SlickPwner 534 — 9y
0
Thanks faruque 30 — 9y

1 answer

Log in to vote
1
Answered by
LevelKap 114
9 years ago

easy! just use body velocity. Here's an example of a fireball script i made, this is in a local script btw. Just change the ball into a bullet and make it come from your gun instead of your torso!

Player = game.Players.LocalPlayer
Char = Player.Character
Torso = Char.Torso
Mouse = Player:GetMouse()

function onKeyDown(key) 
        key = key:lower()
        if key == "v" then
                Ball = Instance.new("Part")
                Ball.Parent = Workspace
                Ball.Shape = "Ball"
                Ball.Size = Vector3.new(5,5,5)
                Ball.BrickColor = BrickColor.new("Really red")
                Ball.Transparency = 0.4
                Ball.TopSurface = 0
                Ball.BottomSurface = 0
                Ball.CFrame = Torso.CFrame * CFrame.new(0,0.5,-5) 
                Bv = Instance.new("BodyVelocity")
                Bv.Parent = Ball
                Bv.maxForce = Vector3.new(math.huge,math.huge,math.huge)
                Bv.velocity = Torso.CFrame.lookVector * 100
    end
end
Mouse.KeyDown:connect(onKeyDown)
0
Thank you for showing me this but I already fixed the problem but again thanks anyways for trying to help I really appreciate it!! faruque 30 — 9y
Ad

Answer this question