Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Gun recoil stops the camera for a second?

local ran = math.random(-200, 200)/10000
local TS = game.TweenService
local goal = {}
goal.CFrame = camera.CFrame * CFrame.Angles(0.03, ran, 0)
local tinf = TweenInfo.new(0.05)
local tween = TS:Create(camera, tinf, goal)
tween:Play()

This is the code that I use for the recoil. If I stand still, it works perfectly, but if I move and shoot, the camera stops, then moves up a bit (how it should), then teleports back to the character. I know that the problem is that the tween animates the whole camera, not only the rotation, but I don't know how to fix it. Is there a CFrame.Rotation or CFrame.Angle that I can use?

Sorry for my English and thanks for any help.

3 comments

0

Why are you using tweens in RenderStepped?

0

@Dovydas1118 Im not. It's inside a mouse click event

0

Have you tried creating the goal inside the TS:Create instead of referencing beforehand?

1 answer

You should never use tweens for animating things that run quickly, as .RenderStepped. What you could do is a for loop inside a coroutine. Some things I'd like to point out is you didn't use the math.rad function which you need to use for CFrame.Angles, and that you could shorten the line using the *= operator.

coroutine.wrap(function()
     for i = 1,10,1 do -- adjust this
          camera.CFrame *= CFrame.Angles(0,math.rad(0.03),0) -- adjust this too
     end
end)() -- keep the brackets as it will make the coroutine run

I don't have experience with making smooth viewmodels, I'm more of a spring user, but this should work.

1 comment

0

The recoil only happens when the player shoots. And the problem with loops is that even if I add a wait(0.01) it's not smooth or it's slow. That's why I used tweening. But that animates the whole camera, not just the orientation.

This discussion is preserved as it was. New answers, comments, and votes are closed.