How to detect Cframe moving by a specific amount

basically, i have this “motion blur” script that detects if the CFrame moves by ANY movement:

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) --// zero doesn't delete it instantly, it's just the lowest amount of time possible
end)

the problem is, it detect any movement, but it being motion blur, thats not how motion blur works, is there a way to detect if it moves by a number or vector3?

1 Like

You could implement sanity checks for every time the CFrame changes to check if the Position/X/Y/Z values are what you want them to be?

local blurness = 5 --//how blurry the motion blur should be, which is the BlurEffect's size
workspace.CurrentCamera:GetPropertyChangedSignal("CFrame"):Connect(function()
    local CamPosition = workspace.CurrentCamera.CFrame.Position

    if CamPosition.X > 50 then
    	local motionBlur = Instance.new("BlurEffect", game.Lighting)
        motionBlur.Size = blurness
        game:GetService("Debris"):AddItem(motionBlur, 0) --// zero doesn't delete it instantly, it's just the lowest amount of time possible
    end
end)

Not sure though

3 Likes

Save the current CFrame in a variable in the script, and check how much it moved by a bit of math, if its greater then a certain number, then motion blur it?

1 Like

is there any better way to do this? (my script) its obviously not optimized when you see blur effects duplicating by 100 everytime the camera moves

how would i check how much it moved?

Vector3 - Vector3 = distance it moved, save the Vector3 or CFrame in a variable at the top of the script before it changes and then compare it.

1 Like

ugh im stuck:

local currentCamera = workspace.CurrentCamera
local CamVector3 = workspace.CurrentCamera.CFrame.Position
local blur = game.Lighting:WaitForChild("Blur")
local runService = game:GetService("RunService")
runService.Heartbeat:Connect(function()
	local result = CamVector3 - CamVector3 
	if result >=5 then 
		game.Lighting:WaitForChild("Blur").Size = 10
	end
end)

i get this error: Players.F0xBirdman.PlayerScripts.LocalScript:7: attempt to compare number and Vector3

on the side, i noticed this: while wait() do print(CamVector3) end prints the same position over and over, even with the camera moving Screen Shot 2021-04-28 at 8.41.14 PM

Um, that’s not what I meant, when it changes compare the two values and see how much it changed by, if it’s greater then 5 or whatever then set the camvector3 once the comparison is done.

local currentCamera = workspace.CurrentCamera
local CamVector3 = workspace.CurrentCamera.CFrame
local blur = game.Lighting:WaitForChild("Blur")
local runService = game:GetService("RunService")
CurrentCamera:GetPropertyChangedSignal("CFrame"):Connect(function()
	local result = CurrentCamera.CFrame - CamVector3
	if result >=5 then 
		game.Lighting:WaitForChild("Blur").Size = 10
	end
        CamVector3 = CurrentCamera.CFrame
end)

im aware thats not what you meant, thats why i said “im stuck”; anything ive tried i get the same error or similar Players.F0xBirdman.PlayerScripts.LocalScript:7: attempt to compare number and Vector3
noticing that you edited your post to a script, same error i have been getting. this was my latest attempt:

local currentCamera = workspace.CurrentCamera
local CamVector3 = workspace.CurrentCamera.CFrame.Position
local blur = game.Lighting:WaitForChild("Blur")
local runService = game:GetService("RunService")
workspace.CurrentCamera:GetPropertyChangedSignal("CFrame"):Connect(function()
	local result = currentCamera.CFrame.LookVector - currentCamera.CFrame.LookVector
	if result >=5 then 
		game.Lighting:WaitForChild("Blur").Size = 10
	end
end)

Simple! Each RenderStep, get the delta (change) of the CFrame since the last frame. Then, assemble it into one number (you can do this multiple different ways) and assign the blur effect to that number.
I would give a code example but I’m on mobile right now…
Well I’m going to try anyways.

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

local Camera = workspace.CurrentCamera
local BlurEffect = Lighting:WaitForChild("Blur")

local lastCameraCframe = Camera.CFrame

RunService.RenderStepped:Connect(function()
    local RotDifference = (Camera.CFrame:ToOrientation() - lastCameraCframe:ToOrientation()).Magnitude
    lastCameraCframe = Camera.CFrame
    BlurEffect.Size = RotDifference * 3
end)
1 Like

most of the problem is that im having trouble finding the change as you can see in my last posts

1 Like

I edited my post, see how that code works out.

1 Like

Players.F0xBirdman.PlayerScripts.LocalScript:10: attempt to index number with 'Magnitude'
you cant use magnitude with the camera, can you?

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

local Camera = workspace.CurrentCamera
local BlurEffect = Lighting:WaitForChild("Blur")

local lastCameraCframe = Camera.CFrame

RunService.RenderStepped:Connect(function()
    local v3 = Vector3.new

    local RotDifference = (v3(Camera.CFrame:ToOrientation()) - v3(lastCameraCframe:ToOrientation())).Magnitude
    lastCameraCframe = Camera.CFrame
    BlurEffect.Size = RotDifference * 3
end)

Try this?

1 Like

no errors, but also no blur effect

Try printing what RotDifference is.

GetPropertyChangedSignal doesn’t fire for fast changing properties like CFrames and Positions except when you change them explicitly.

If you want to check how much the camera moved from it’s starting point, you can get just simply get the distance from it’s starting point to it’s current:

local startingCamPos = workspace.CurrentCamera.CFrame.Position  -- get the position at starting point

game:GetService("RunService").Heartbeat:Connect(function()
      local distance = (startingCamPos - workspace.CurrentCamera.CFrame.Position).Magnitude

     if distance  > = 5 then 
		game.Lighting:WaitForChild("Blur").Size = 10
	end
end)

it prints around the 0 range Screen Shot 2021-04-28 at 9.53.54 PM but i guess it seems to work? when i dont move the camera it prints 0, which is good

Try changing the multiplier to 200 or 400
Actually thats probably a bit too high lol

1 Like

when i used it, it fired perfectly, also the blur stays at 10, even with an else