What do you want to achieve?
I’m trying to create a screenshake effect using tweenservice and camera rotation.
What is the issue?
Whenever I try to tween the camera’s rotation, it appears to “snap” itself back into
its original position. How would I tween the rotation without having it snap the position?
3. Example:
Code:
local function offset(rotation,duration)
local propertieschanged = {
CFrame = rotation
}
local info = TweenInfo.new(duration,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)
local tween = tweening:Create(cam,info,propertieschanged)
tween:Play()
end
offset(cam.CFrame * CFrame.Angles(0,-0.02,0),0.05)
(only a small segment of the actual code, but i only included the important bits)
What solutions have you tried so far?
I’ve attempted to search for solutions regarding this issue, however I struggle with finding anything related to my exact situation or anything I can properly apply to my situation.
Hi, thanks for the help and reference to the cool module. However, I’d prefer to find out how to code screenshake myself rather than using a free module
Nope, this is completely default. The only other thing that possibly could be related to the camera is that I have the mouse targetfilter set to a folder called “Effects” in the workspace which holds effects. However, this wouldn’t and shouldn’t cause anything.
Alright. I think this is the most “smooth” that you’re going to get this.
However, you could save the Y component of the camera CFrame before the “effect” occurs and then tween to that Y as well as new X and Z after the effect has finished. But that is very hacky and may not result in a smooth effect.
I can’t tell you exactly why this is happening, seeing as all the other CFrames tween just fine I see no reason why it wouldn’t tween to the original.
After playing with the script a bit, I found that setting the CameraType to Scriptable while the screen is shaking and reverting back to Custom afterwards worked perfectly.
When modifying the camera in any way via scripts, I’d always recommend using the Custom option as this will ensure no other behaviour will affect your desired result.
CameraType has to be Scriptable to roll the camera at all. All other modes will internally “correct” the camera to be level with the horizon. The exception is if you use Camera:SetRoll() which uses an additional transform applied after the Camera.CFrame, but this is essentially deprecated so not recommended for new work. Scriptable is the way to go.