I am attempting to add a camera shake to my current games weapons. I have made it so whenever the weapon is fired a shake function is activated which shakes the players camera, though I have ran into a strange problem where if the camera shake is called before it ends it will cause a stray bullet to appear (mostly happens when the weapon is automatic). This stray bullet is an outlier to where the bullet should land. This does not happen when the spread function is taken away. Here is how the shake is created and called:
function camShake() local Intensity = weaponSettings.cameraShake.Value for i = 1, 10 do local cam_rot = Camera.CoordinateFrame - Camera.CoordinateFrame.p local cam_scroll = (Camera.CoordinateFrame.p - Camera.Focus.p).magnitude local ncf = CFrame.new(Camera.Focus.p)*cam_rot*CFrame.fromEulerAnglesXYZ((-Intensity+(math.random()*(Intensity*2)))/100, (-Intensity+(math.random()*(Intensity*2)))/100, 0) Camera.CoordinateFrame = ncf*CFrame.new(0, cam_scroll, 0) wait() end end function FireBullet() RemoteStorage.fireEvent:FireServer(Part, Position, Distance, Mouse.Hit.p, Weapon ,ray, bulletSettings.bulletDamage.Value, bulletSettings.bulletSpread.Value, weaponSettings.magNumber.Value, weaponSettings.reloadTime.Value, bulletSettings.bulletSpeed.Value) --fires raycasting information to server spawn(camShake) --spawns the shake event end
Here is a gif of the weapons with and without the shake function:
With Camera shake:
Without Camera shake:
Im pretty sure this has to do with the buildup of many camera shake functions at once but I unsure. Could anyone help?