So basically this script detects if an explosion occurs at all and if it's position is close enough it will shake the camera around simulating what you would feel/see in real life if you were caught near an explosion. However, when the camera shakes and I move around, it seems to not follow the player and it sometimes turns to the side and it's really weird. Any way to fix that? this is my script. just pop this whole thing in a localscript in starterplayerscripts.
workspace.ChildAdded:connect(function(explosion)
if plr and plr.Character and plr.Character:FindFirstChild("Torso") and explosion:IsA("Explosion") and (explosion.Position - plr.Character.Torso.Position).magnitude < 50 then
workspace.CurrentCamera.CameraType = "Scriptable"
local oldsubject = workspace.CurrentCamera.CameraSubject
local oldcframe = workspace.CurrentCamera.CFrame
game:GetService("RunService"):BindToRenderStep("Update", Enum.RenderPriority.Input.Value + 1, function()
workspace.CurrentCamera.CameraSubject = plr.Character.Head
end)
local value = 0 -- 3.5
local p = 2
for i = 1,10 do
wait(0.1)
if plr.Character:FindFirstChild("Head") then
value = value + p
p = p - 0.2
if workspace.CurrentCamera.CameraType == Enum.CameraType.Scriptable then
workspace.CurrentCamera:Interpolate(workspace.CurrentCamera.CFrame + Vector3.new(0, 0, 0), plr.Character.Head.CFrame + Vector3.new(0, value, 0), 0.05)
end
wait()
value = value - p
p = p - 0.2
if p < 0 then
break
end
if workspace.CurrentCamera.CameraType == Enum.CameraType.Scriptable then
workspace.CurrentCamera:Interpolate(workspace.CurrentCamera.CFrame + Vector3.new(0,0,0), plr.Character.Head.CFrame + Vector3.new(0,value,0), 0.05)
end
end
end
workspace.CurrentCamera.CFrame = oldcframe
workspace.CurrentCamera.CameraType = "Fixed"
workspace.CurrentCamera.CameraType = "Custom"
if oldsubject then
workspace.CurrentCamera.CameraSubject = oldsubject
else
workspace.CurrentCamera.CameraSubject = plr.Character.Humanoid
end
game:GetService("RunService"):UnbindFromRenderStep("Update")
end
end)
