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

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

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)

2 comments

1

Add a BodyGyro. I suggest looking up how to use it on the Wiki, it stabilizes bricks.

0

Thanks

1 answer

✓ Accepted answer

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)

1 comment

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!!

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