How do I add motion blur to my games?

Hello it’s me and I want to ask the dev forums on how to add motion blur on games, especially on making first person games like horror games.

Please also let me know if I’m in the wrong section

4 Likes

Just add the object called “Blur” in Lighting

Isn’t that just a blur effect?

Motion blur is usually done with Bloom

2 Likes

you can check whenever the camera is moved and add a blur effect to simulate motion blur

local blurness = 5 --//how blurry the motion blur should be, which is the BlurEffect's size
workspace.CurrentCamera:GetPropertyChangedSignal("CFrame"):Connect(function()
	local motionBlur = Instance.new("BlurEffect", game.Lighting)
    motionBlur.Size = blurness
    game:GetService("Debris"):AddItem(motionBlur, 0) --//fun fact, zero doesn't delete it instantly, it's just the lowest amount of time possible
end)

note that this implementation creates motion blur every time the CFrame property of the camera is changed, which may include unintended side-effects like causing motion blur when moving but you should be able to make a better implementation that prevents ordeals like these using mouse position and the likes
edit: please use the implementation a few comments below if you want a traditional mouse based motion blur

17 Likes

you have to get the magnitude of the camera moving and divide that by 2. Then you have to set the Blur Effect strength to whatever magnitude / 2 is.

1 Like

I think it’s not gonna work because blur is an effect, motion blur is when like when you move, the objects in workspace will go blurry just like in real life when there are moving things

pardon me if I didn’t made much sense

Sorry because i only know the original blur effect

I tried doing it in a server script and it doesn’t seem to work yet but I’ll try to also try the code into a local script

1 Like

yes it works thank you for that!

the camera can only be manipulated on the client-side, if you change it server-side only the server will see the effect, which fun fact will works if you go to server view in studio testing

2 Likes

one more question @RoyalTHEUSERNAME how do you only make the bloom effect when the player only rotates his head / camera not for walking.

you can use the MouseMovement input type of UserInputService to detect when the player moves their mouse and using the input’s delta to determine if the camera was dragged (in this case if the mouse delta isn’t a blank Vector3 the camera is being dragged)

local blurness = 5
game:GetService("UserInputService").InputChanged:Connect(function(input, gameProcessedEvent)
	if input.UserInputType == Enum.UserInputType.MouseMovement and input.Delta ~= Vector3.new() then --//checking the input type and delta to see if the camera is being dragged
		local motionBlur = Instance.new("BlurEffect", game.Lighting)
		motionBlur.Size = blurness
		game:GetService("Debris"):AddItem(motionBlur, 0)
	end
end)

as a bonus you can check the delta to find how fast the camera is currently being moved to implement what @Discgolftaco231 mentioned
however do note that this will only work when the camera is moved with a mouse, you’d have to use something else for mobile and controller users such as TouchPan

3 Likes

basically, run by frames, and get the magnitude from the position of the camera before the current frame, and during the current frame, and then times that magnitude by a set amount around 100. To make this operation smoother i am going to run another task.

since I’m running by the user’s frames, I’m going to first, get the framerate, then take the speed that I want the blur to increase until it hits the designated blur amount (0.5). The formula would go like this: framerate*0.5. this would give the needed result. For example, 60 fps would be 30. now take the result and simply divide by the framerate (30/framerate) and use it as the increment to increase or decrease to the needed blur amount.

Also, make sure to insert a blur effect to lighting and set the size to 0, this script would go anywhere that I will be parented by the player (starterGui, starterPack, starterPlayerScripts, etc…)

local player = game.Players.LocalPlayer
local lastframe = game.Workspace.CurrentCamera.CFrame
local fps = 60
local countfps = 0
local startTest = tick()
game:GetService("RunService").RenderStepped:Connect(function()
	countfps = countfps+1
	if tick()-startTest>=1 then
		fps = countfps
		startTest = tick()
		countfps = 0
	end
	local cam = workspace.CurrentCamera
	if cam then
		local frame = cam.CFrame
		local dist = (frame.LookVector.Unit-lastframe.LookVector.Unit).Magnitude
		--print(6/fps)
		if game.Lighting.Blur.Size<dist*100 then 
			game.Lighting.Blur.Size = game.Lighting.Blur.Size+30/fps 
		else 
			if game.Lighting.Blur.Size > dist*100 then
				game.Lighting.Blur.Size = game.Lighting.Blur.Size-30/fps
			else
				game.Lighting.Blur.Size=dist*100 
				print("on point") 
			end
		end 
		lastframe = frame
	end
end)
7 Likes

Bump, I notice the motion blur scripts they use are not at all of a good standard. So here you go:

local RunService : RunService = game:GetService("RunService")

local Blur_Effect_Enabled : boolean = true
local Blur_Intensity_Multiplier : number = 5

if Blur_Effect_Enabled then
	local Blur_Effect_Instance : DepthOfFieldEffect = Instance.new("DepthOfFieldEffect", Current_Camera)
	Blur_Effect_Instance.Name = "Motion_Blur"
	
	Blur_Effect_Instance.FarIntensity = 0
	Blur_Effect_Instance.FocusDistance = 10
	Blur_Effect_Instance.InFocusRadius = 10
	Blur_Effect_Instance.NearIntensity = 0
	
	RunService.RenderStepped:Connect(function()
		local Camera_Blur_Magnitude = (Current_Camera.CFrame.LookVector - Previous_LookVector).Magnitude
		Blur_Effect_Instance.FarIntensity = math.clamp(math.abs(Camera_Blur_Magnitude) * Blur_Intensity_Multiplier, 0, 1)
		Blur_Effect_Instance.NearIntensity = 0 --Blur_Effect_Instance.FarIntensity
		Previous_LookVector = Current_Camera.CFrame.LookVector
	end)
end

Use at own risk as it does cause LAG for certain devices that cannot handle it.

EDIT: Place in StarterPlayer > StarterPlayerScripts!