Turrent bullet going downward

I was making a turrent that shoots bullet but the bullet goes downward

Any help is appreciated

script here

local repstorage = game:GetService(“ReplicatedStorage”)

local bullet = repstorage:WaitForChild(“Bullet”)

local turrent = script.Parent

local firerate = 0.5
local damage = 5
local speedbullet = 150
local agrodistance = 300

while wait(firerate) do

-- find target detect if its real to shoot

local target = nil

for i, v in pairs(game.Workspace:GetChildren()) do
	local human  = v:FindFirstChild("Humanoid")
	local torso = v:FindFirstChild("Torso")
	if human and torso and human.Health > 0 then
		if (torso.Position - turrent.Position).magnitude < agrodistance then
			target = torso
		end
	end
end

if target then
	local torso = target
	turrent.CFrame = CFrame.new(turrent.Position, torso.Position)
	
	local turrentbullet = bullet:Clone()
	turrentbullet.Position = turrent.Position
	turrentbullet.Parent = game.Workspace
	
	
	turrentbullet.Velocity = turrent.CFrame.LookVector * speedbullet
	
	
	turrentbullet.Touched:Connect(function(objecthit)
		local human = objecthit.Parent:FindFirstChild("Humanoid")
		if human then
			human:TakeDamage(damage) 
		end
	end)
	
end

end

Hello J4Y,

Your bullets are affected by gravity. You would need to create a force to keep it floating.

Insert the following code between the bullet creation line and the velocity line:

local turrentbullet = bullet:Clone()
turrentbullet.Position = turrent.Position
turrentbullet.Parent = game.Workspace
	
local attach = Instance.new("Attachment")
attach.Parent = turrentbullet

local force = Instance.new("VectorForce")
force.Attachment0 = attach
force.Force = Vector3.new(0,turrentbullet:GetMass() * workspace.Gravity,0)
force.ApplyAtCenterOfMass = true
force.Parent = turrentbullet
	
turrentbullet.Velocity = turrent.CFrame.LookVector * speedbullet
2 Likes