Bullet isn't cast until the gunfire animation hits the apex

Hey, so I’m working on a fps and I’ve came across this issue, the bullet isn’t cast until the apex of the gun animation. Here is a video to show you:

As you can see, the bullet doesn’t come out until the gun is at the highest point of the animation (apex). Here are the scripts:
Fire function:

local function fire(toFire,gunName)
	
	if equipping then return end
	if reloading then return end
	if not player.Character then return end
	if toFire and ammo[currentViewmodel.values.Slot.Value].ammo <= 0 then firing = false end
	if not canFire and toFire then return end
	
	firing = toFire
	
	if not toFire then return end
	
	local function shoot()
		
		if ammo[currentViewmodel.values.Slot.Value].ammo <= 0 then return end

		local sound = currentViewmodel.fireSound:Clone()
		sound.Parent = currentViewmodel
		sound:Play()

		game:GetService("Debris"):AddItem(sound,5)

		local anim = currentViewmodel.animControl:LoadAnimation(currentViewmodel.clientAnimations.fire)
		anim:Play()
		
		ammo[currentViewmodel.values.Slot.Value].ammo -= 1
		
		player.PlayerGui.ammoGui.backG.ammoCounter.Text = ammo[currentViewmodel.values.Slot.Value].ammo.." / "..ammo[currentViewmodel.values.Slot.Value].max

		recoil:shove(Vector3.new(0.03,0,0 * deltaTime * 60))

		spawn(function()

			wait(0.15)
			recoil:shove(Vector3.new(-0.02,0,0) * deltaTime * 60)

		end)

		local origin = currentViewmodel.barrel.barrelAttachment.WorldPosition
		local direction = currentViewmodel.barrel.barrelAttachment.WorldCFrame

		fastCastHandler:Fire(origin,direction)

		wait(60/currentViewmodel.values.RPM.Value)
		
	end
	
	repeat
			
		canFire = false
		
		shoot()
		
		canFire = true
		
	until ammo[currentViewmodel.values.Slot.Value].ammo <= 0 or not firing or reloading
	
	if reloading then firing = false end
	
	if ammo[currentViewmodel.values.Slot.Value].ammo <= 0 then firing = false canFire = true end
	
end

Where the function is fired:

uis.InputBegan:Connect(function(key,gpe)
	
	if gpe then return end
	
	if key.UserInputType == Enum.UserInputType.MouseButton1 then
		
		fire(true,curEquipped)
		
	end

end)

And the FastCast handler:

function fastCastHandler:Fire(origin,direction,properties,IsReplicated,repChar)
	
	local rawOrigin = origin
	local rawDirection = direction
	
	local directionalCFrame = CFrame.new(Vector3.new(),direction.lookVector)
	direction = (directionalCFrame * CFrame.fromOrientation(0,0,random:NextNumber(0,math.pi * 2)) * CFrame.fromOrientation(0,0,0)).LookVector
	
	local bullet = rs.bullet:Clone()
	bullet.CFrame = CFrame.new(direction,origin + direction)
	bullet.Parent = workspace.fastCast
	bullet.Size = Vector3.new(0.05, 0.05, 1200/200)
	
	local id = math.random(-10000,10000)
	local idValue = Instance.new("NumberValue")
	idValue.Name = "id"
	idValue.Value = id
	idValue.Parent = bullet
	
	bullets[id] = {
		
		Properties = properties,
		replicated = IsReplicated
		
	}
	
	if not IsReplicated then
		
		gunRemotes.fire:FireServer(rawOrigin,rawDirection,id)
		
	end
	
	local list = {
		
		workspace.Camera,
		workspace.CurrentCamera,
		players.LocalPlayer.Character,
		players.LocalPlayer.Character.HumanoidRootPart
		
	}
	
	mainCaster:FireWithBlacklist(origin,direction * 5000, 200, list, bullet, true, Vector3.new(0,rs.gravity.Value,0))
	
end

Everything works, no errors, it’s just the problem described at the top of the post.
Thanks in advance!

Try putting the function where the gun is shooted before the animation. I think that should fix the problem.
That in case the shot is in the same script of the animation

1 Like

I’ve put it after the :Fire() function of the FastCast handler is fired, but it changed nothing.

The bullet doesn’t have like a time before casting?

1 Like

You should read the script carefully, the only lines that contain wait() in them are

and

which in this case is inside a spawn which doesn’t affect the guy firing.

The bullet seems to be coming from below, and it doesn’t seem very fast either. try making the projectile bigger (to check where it’s coming from) and checking the velocity

1 Like

1.I think the bullet comes from below because the attachment is on the barrel, though it doesn’t matter as it doesn’t come out anyway as described in the post.
2. Made the bullet a giant block, but looks like FastCast automatically resizes it.
3. I’ve specially made it low (200) because at first I thought it was so fast I wasn’t able to see it. Made it high again but the problem persists.

1.that makes no sense

  1. you’re resizing it (fastcast literally does nothing to your bullets other than provide them as an argument in a function)
    image

  2. A normal bullet velocity is higher than 1000, the video doesn’t seem to have it that high

also, add workspace.fastCast in your ignore list

2 Likes

image
2. Resized it in the script, put the velocity to 1200, added workspace.fastCast to the list, commented the line that plays the animation. Here’s the result:


This is mindblowing, maybe it’s something in

Though I can’t see why it would be delaying that.

it looks as if it’s going backwards, the repeat loop has nothing to do with it as well

1 Like

Now I’ve put a print on everything that makes it shoot (fire function, FastCast handler and inside FastCast itself) and everything prints ok, but the bullet still doesn’t come out. Also, just noticed the “failed” bullets go into the fastCast folder, and when I clone them and paste into the non-running game, they’re in random positions. Looks like I am gonna have to completely rewrite my script, seems like the only solution.

are the bullets anchored

Yes, they are. But I unchecked it and it’s still the same thing.

I had the same issue when i used BIackShibe framework, and i think its simply because the gun are unachored and its actually falling into the ground but we are not noticing it because of the update per frame, but if you see in the properties window you will see the position continuously changing. Correct me if i am wrong.

1 Like

I rewrote everything from the ground up a few months ago, and never knew what it actually was, but it might be actually what you’re suggesting (although I don’t have the scripts and models to test it). I’ll mark your answer as the solution (^▽^)

1 Like