Hi, I’m making a camera shake effect for some guns using TweenService and I’ve come into a problem: My method affects the Camera’s position, which I do not want. What I want to do is to ONLY rotate the camera’s CFrame and leave the position unaffected.
Here’s the code sample below (X, Y, Z are all just angle values to shake the camera)
local TweenService = game:GetService("TweenService")
local Info = TweenInfo.new(0.075, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, true, 0)
game.ReplicatedStorage.RemoteEvents.CameraShake.OnClientEvent:Connect(function(X, Y, Z)
local Goal = {}
Goal.CFrame = workspace.CurrentCamera.CFrame * CFrame.Angles(X, Y, Z)
local Tween = TweenService:Create(workspace.CurrentCamera, Info, Goal)
Tween:Play()
end)
I’ve tried several solutions, but they don’t work. Here’s my changes and results:
Fix: Using the above code
Result: Rotation works perfectly, but the position gets offset for a moment (I’m using a First-Person ViewModel, so I think the Tween is what’s making it offset like that)
Fix: Changing Goal.CFrame
to Goal.CFrame.Rotation
and deleting workspace.CurrentCamera.CFrame
so it’s only the CFrame.Angles
part remaining.
Result: Gives an error stating ‘attempt to index nil with “Rotation”’. Apparently I can’t use that property of CFrame as a goal in a Tween array.
Fix: Everything same as code sample, but I only left the CFrame.Angles
part alone.
Result: Camera’s position goes to the origin of the world, screwing up everything entirely.
I’m out of ideas, can someone help me?
Thanks