i think its prolly because when you made the tween the camera position you set stays the same so the tween will move you back to your previous position that is why when you stand still it wont go behind the player
so you should probably use a Lerp instead heres an example (i havent tested it yet)
local recoil = CFrame.new()
---- render stepped function im too lazy to tyype
recoil = recoil:Lerp(cframe stuff,0.2) -- the 0.2 is how smooth, the smaller it is, smoother
camera.CFrame *= recoil
This is good but it doesn’t have that same look that the old recoil did and it doesn’t reverse. How can I reverse it and why does it look a little different than before?
Old Look:
Code I put:
local recoil = CFrame.new()
local oldCameraCFrame = Camera.CFrame
local con; con = game["Run Service"].RenderStepped:Connect(function()
recoil = recoil:Lerp(CFrame.Angles(math.rad(math.random(2, 5)), math.rad(math.random(-3, 3)), 0), 0.05)
Camera.CFrame *= recoil
task.spawn(function()
task.wait(0.05)
if (con) then
recoil = recoil:Lerp(oldCameraCFrame, 0.1)
con:Disconnect();
end
end)
end)
I understand you’ve switched between multiple codes,
We didn’t get to know if the less cooler Lerp code you were
given worked while moving player position.
If it did, and was a lerp code, please provide it and I’ll try to replicate it more to what it looked like with your old Tween.
TweenService is not suitable for tasks like these, as it will go through the start and end values while you’re moving, which causes the camera to go behind during recoil. I highly recommend using springs for this, as they can adapt to constantly changing values while applying some kind of force. I would recommend checking out a first person shooter tutorial. For example:
Here is also my example to get you started:
local recoilSpring = Spring.new({
Damper = 1,
Speed = 10
})
-- To be called whenever a gun is fired
local function shoot()
recoilSpring:Impulse(Vector3.new(-3, 0, 0))
end
-- To be called every frame
local function update(dt: number) -- dt: delta time
local recoil = recoilSpring:Update(dt)
camera.CFrame *= CFrame.Angles(recoil.X, recoil.Y, recoil.Z)
end