Bullet Velocity does not go in the direction of where it was shot

Hello!

I have a gun script which shoots out bullets which are supposed to shoot in the direction of the mousepos.

local RS = game:GetService("ReplicatedStorage")
local RunS = game:GetService("RunService")

local Velocity = 250
local Time
local Gravity = workspace.Gravity


RunS.Heartbeat:Connect(function(dt)

	Time = dt
end)

RS.Events.Gunshot_Event.OnServerEvent:Connect(function(Player,GunName,MouseShotPosition,GunModel)
	local Axis = MouseShotPosition
	
	local Bullet = game.ReplicatedStorage.GunVFX.Bullet:Clone()
	Bullet.Parent = workspace.GameFolders.Bullets
	Bullet.CFrame = GunModel.Barrel.CFrame

	
	local S = Velocity*Time
	local s = Time-((1/2)*Gravity*(Time*Time))
	Bullet.AssemblyLinearVelocity = Vector3.new(0,s,S)
	
end)

Right now, all its doing right now is falling into the void, which isnt what I want.

How would I make it move and also go to the direction of the mousepos?

Thanks.

1 Like

Try changing to this:

Bullet.CFrame = CFrame.new(GunModel.Barrel.CFrame.Position, MouseShotPosition)

	if Time == 0 then
		Time = 0.1
	end
	local S = Velocity*Time
	local s = Time-((1/2)*Gravity*(Time*Time))
	Bullet.AssemblyLinearVelocity = (Bullet.CFrame.LookVector * S) + Vector3.new(0, s, 0)

EDIT: I just noticed that no velocity was being applied in the video.

1 Like

I already solved this issue myself [using a different method of applying velocity] but thanks for trying! :slight_smile: