MouseDelta but for Camera instead

currently working on scope shadow, i calculate scope shadow using the mouse delta but id like the shadow to move with the camera rather than the mouse. i would need a way to transform camera movement into a delta and it should go back to 0 again once cam stops moving. ability to extrapolate X and Y delta as well

just like mouse delta and it would have to behave like mousedelta for functionality, anybody know a way?

Check if the Camera CFrame is moving.

I’m confused, is the camera moving on a 2D plane? Do you need to calculate this when the camera stops moving or during each render step?

id have to calculate each renderstep, i want to replicate what userinputservice:GetMouseDelta() does, but instead of it returning the mouse delta it returns a sort of ‘camera’ delta. a vector2 with the x and y value which turn to 0 if camera stops moving, just like mousedelta if you stop moving the mouse

im looking to replicate exact userinput:getmousedelta() functionality but instead with mouse with camera

Since the Camera’s position is represented by a CFrame, you can’t represent it as a Vector2. However, you can still get its Delta by multiplying the inverse of the current CFrame to the one from the last frame (Essentially subtracting).

local CameraDelta: CFrame = CFrame.identity
local CameraLast: CFrame = CurrentCamera.CFrame

local function UpdateDelta(): () -- Hook with Camera priority or something
	CameraDelta = CurrentCamera.CFrame:Inverse() * CameraLast
	CameraLast = CurrentCamera.CFrame
end
1 Like

thank you this is a great start i have a question tho, how would i extract X and Y delta
so that i may multiply specific other values with the delta X value for example?

Well, a CFrame has positional and rotational data, so it depends on what you are trying to do. I would say if you’re trying to get the rotational delta you should use CameraDelta:ToEulerAnglesXYZ() and get the returned X and Y values.

the code you sent me is very great, just one more thing is missing and that is how would i reset the delta to 0 again like mousedelta, as in it moves, the delta jumpes from 0 to 6 and then back to 0 again

What exactly are you asking? The camera’s position delta? I’m just confused by what you mean to convert it into a Vector2.

yeah the cameras position delta, ill edit vector2 it out since i just threw that in there because of the correlation to it to mouse delta

Alright, sorry. That would’ve just worked for the positional values for the CFrame.

I believe this is what you want:

local X1, Y1 = CurrentCamera.CFrame:ToEulerAnglesXYZ()
local X2, Y2 = CameraLast:ToEulerAnglesXYZ()

local Delta = Vector2.new(X1 - X2, Y1 - Y2)

CameraLast = CurrentCamera.CFrame
2 Likes

Is a delta between each frame what you wanted?


local player = game.Players.LocalPlayer

local camera = workspace:WaitForChild("Camera")

local mouse = player:GetMouse()


local lastPos = camera.CFrame.Position
mouse.Move:Connect(function()
	local diff = camera.CFrame.Position - lastPos
	lastPos = camera.CFrame.Position
	if diff.Magnitude > 0 then	
		print("Camera move: "..tostring(diff))
	end
end)
1 Like

yeah thanks so much man this worked, thanks to others who tried to help as well

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