Hello! I would just like to know how to check if an object (specifically the camera) is currently rotating. It would help a lot and help is appreciated. thank you!
By this I assume you mean how do you check if the player is currently moving their camera around?
You could connect some code in a localscript to RunService.RenderStepped
, and hold onto the last frames Camera.CFrame.Rotation
, then do a fuzzyeq check to see if they are the same or not. (Camera.CFrame.Rotation:FuzzyEq(LastCFrame, .01)
)
cframe1:FuzzyEq(cframe2, number)
returns true if cframe1
and cframe2
are so similar to eachother, number
has to be at or below .1 and determines how close they have to be to return true.
I did this
game:GetService("RunService").RenderStepped:Connect(function()
local cCFrame = cam.CFrame
local LastCFrame
task.wait()
LastCFrame = cCFrame
local rotating = cam.CFrame.Rotation:FuzzyEq(LastCFrame, 0.1)
print(rotating)
task.wait()
end)
but it didn’t work, it kept printing false no matter what
added some comments to explain the modifications, if it doesn’t make sense then ask and I can explain further on whats confusing.
local LastCFrame = nil -- create it ouside of the connection
game:GetService("RunService").RenderStepped:Connect(function()
local cCFrame = cam.CFrame
-- this is for the first time, since it will start as nil.
if not LastCFrame then LastCFrame = cCFrame end
-- needs to have a `not` since it returns true if they aren't
-- rotating. Also changed to LastCFrame.Rotation since before
-- it was also comparing their positions, which caused the false
-- issue
local rotating = not cam.CFrame.Rotation:FuzzyEq(LastCFrame.Rotation, 0.01)
print(rotating)
-- set our current CFrame to be the lastCFrame, now the next
-- renderstep will have it set to this rendersteps cframe
LastCFrame = cCFrame
end)
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.