Recoil Reset Help

Hey there!
I am trying to cause recoil on a weapon when shot and then return to the point where the spray started (in rotation)

So I tried using springs…

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local mouseheld = false
local cam = workspace.CurrentCamera
local springs = require(game.ReplicatedStorage.Springs)
local v3 = Vector3.new

local upSpring = springs.new(v3())
upSpring.Speed = 20
upSpring.Damper = 1

game:GetService("RunService").RenderStepped:Connect(function()
    cam.CFrame *= CFrame.Angles(upSpring.Position.X,upSpring.Position.Y,upSpring.Position.Z)
end)

local burstCount = 0
local lastShot = 0

mouse.Button1Down:Connect(function()
    mouseheld = true
    
    while wait(1/9.25) and mouseheld do --upward
        local now = tick()
        local duration = now - lastShot
        
        if duration > .5 then
            print("starting new")
            burstCount = 1
        else
            burstCount += 1
        end
        
        lastShot = now    
        
        upSpring.Velocity = v3(1,0,0) 
        wait(.1)
    end 
    
    wait(.8) --retreat
    if not mouseheld then        
        upSpring.Velocity = v3(-1*burstCount,0,0)    
    end 
end)

mouse.Button1Up:Connect(function()
    mouseheld = false
end)

and it works, but doesn’t always end up exactly where the bullet spray started.
I’ve heard people storing Orientation of the camera, then lerping to it after spray, but the problem is that that method is in the wrong if player moves their mouse below the starting rotation, which would make it reset the recoil by going upwards.

I have posted my recent attempts, and haven’t gotten any help. Hopefully you can solve my problem :slight_smile:
(also feel free to copy paste in a localscript and run the above code)

1 Like

You are already using a spring, which by default will try to return to its target point of a Zero Vector. This is seemingly the only reason you would be using a spring. Why are you still trying to apply a negative velocity? This system does not make sense to me. It seems like you’re using a spring system because it would automatically account for this pullback. You can’t achieve this with your camera system because your camera angles aren’t manually accounted for. You have two options essentially.

  1. Rewrite your camera script/render stepped bind to handle camera movement so you have a “look direction” to work with, and the camera position will be this direction combined with the spring rotation

  2. Remove the spring system and statically lerp the camera by x degrees and then back by -x degrees

Can you explain the first point more clearly? Because I have tried doing

local downcf = cam.CFrame * CFrame.Angles(-.1,0,0)
local Rotx, Roty, Rotz = downcf:ToOrientation()

while not shooting or not MouseMoved do
   cam.CFrame = cam.CFrame:Lerp(CFrame.new(cam.CFrame.Position)*CFrame.Angles(Rotx, Roty, Rotz))
end

Also I never knew spring system goes to 0. I set a .Target and it goes to that target is what I thought it’s used for.