Projectile delays behind

I have a plane that shoots bullets but when I shoot while flying, the bullet would sometimes go inside the plane. I set the bullet network to the player and the plane network to the player too.

Shoot Gun: (server)

local ServerStorage = game:GetService("ServerStorage")
local Bullet = ServerStorage:WaitForChild("Bullet")

local model = script.Parent.Parent
local GunPart = model:WaitForChild("GunPart")

local function SetNetworkOwner(part, owner)
	local result = part:CanSetNetworkOwnership()

	if result then
		part:SetNetworkOwner(owner)
	end
end

local function ShootGun(player)
	local newBullet = Bullet:Clone()
	newBullet.CFrame = GunPart.CFrame
	newBullet.Parent = workspace
	
	SetNetworkOwner(newBullet, player)
end

script.Parent.ShootGun.OnServerEvent:Connect(function(player)
	ShootGun(player)
end)

Script inside bullet: (client)

local part = script.Parent

local launchPower = 1000

part.Touched:Connect(function(hit)
	local speed = (part.AssemblyLinearVelocity - hit.AssemblyLinearVelocity).Magnitude
	
	if speed >= 250 then
		script.BreakWeld:FireServer(hit)
	end
end)

part.AssemblyLinearVelocity = part.CFrame.LookVector * (launchPower + part.AssemblyLinearVelocity.Magnitude)

How can I fix this?

I think its because its taking the gunPart’s Cframe and when you fly forwards the position will end up being behind it, if that makes sense. You should also make sure that your own bullets can’t hit your plane.

Example:
GunPart’s CFrame = (0,0,0)
When you fire the bullet the gunPart’s CFrame is now, (5,5,5)
So therefore the bullet will fire behind the gunPart’s current position

So would I predict the next GunPart position using velocity?

I just had to do this:

newBullet.CFrame = GunPart.CFrame + (GunPart.CFrame.LookVector * 10)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.