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?
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
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
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
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)