Bullet starting position doesn't align with the Muzzle current position

So, I’m making an FPS game and run into a problem when I shoot the bullet out of the gun at the Muzzle Position as a starting point. But the if I rotate the camera around fast, the bullet trail position seems to be off comparing to the where the muzzle position currently is.

So as an attempt to fix this problem, I’ve tried to predict where the muzzle will be if we rotate the camera by using a loop and some line of code to figure it out:

local LastMuzzleCFrame = CFrame.new()

RunService.RenderStepped:Connect(function()
	local PredictedMuzzlePosition = (Muzzle.CFrame:ToObjectSpace(LastMuzzleCFrame)).Position
	LastMuzzleCFrame = Muzzle.CFrame
	--Send it to a server
end)

But it didn’t work that well because the same problem still occurs.

I think the reason for this is that you are using ToObjectSpace, which might mess with the position. Try just using Muzzle.CFrame

If you are creating the shot on the server, that is because of network lag, pretty normal in every game, to hide that effect you would have to cast a local bullet.

Takes time for the info to arrive at the server, then the part is created, and another time to go back to clients.

1 Like

Also, that prediction effect you created might make it look normal in the shooter’s screen, but all the other player will se the bullet offsetted when that players shoots.

1 Like

That effect gets really bigger if you are not at studio, shooting from actual game, because in studio your pc is still simulating the server.

1 Like

Yes, and I forgot to mentioned that the PredictedMuzzlePosition is just an add-on to the Muzzle position so the full script is gonna look like this

--ServerSide

remoteevent.OnServerEvent:Connect(function(player, MuzzlePos, PredictedPosition)  -- the current muzzlepos is already included and the Predicted Pos is just an addon to that
 local BulletCurrentPosition = MuzzlePos + PredictedPosition + . . .
end)

I see, this is very interesting, thanks for the advice

There is a setting in Studio also that allows you to simulate a higher network replication lag

1 Like

Yes, now I see that the bullet gets really off due to the replication lag. I think I’ll try the method of rendering the bullet locally

Therefore, I notice fps games like Bad Business for example, their bullet position is pretty much precise to the muzzle position, so do you think that they have the similar approach of casting a local bullet in order to hide the delay?

Bullets are always rendered on the client unless you’re using ancient 2009 tehcnology.

1 Like

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