What do you want to achieve?
I want my side recoil to be the same no matter how high or low you look.
What is the issue?
When you look straight, you turn 180 (which is the SideRecoil value which is infact set to 180) but if you look up it will increase how much side recoil you get.
What solutions have you tried so far?
I have tried using lerp value (0 - 1) to multiply the y and z rotation so that if we are looking up or down only the z would be rotated and if we are looking straight only the y would work but it didn’t fix it and made it even more buggy so I went to the original recoil system.
function Recoil(dt)
if RecoilDeltaTime <= 0 then
LastRecoil = 0
end
RecoilDeltaTime += dt
local RecoilToSine = math.clamp(RecoilDeltaTime,0,Settings.RecoilSpeed) * ((1/Settings.RecoilSpeed))
local NewRecoil = math.sin(((RecoilToSine*math.pi)/2))
Camera.CFrame *= CFrame.Angles(math.rad((NewRecoil - LastRecoil)*Settings.UpRecoil),math.rad((NewRecoil - LastRecoil)*Settings.SideRecoil),0)
LastRecoil = NewRecoil
end
Thank you, while it didn’t fix my issue it pointed me into the correct direction which was turning the cframe to the global axis.
I fixed the issue by
Getting rotation cframe of the recoil and the camera and adding them together
then multiplying it by the cframe position of the camera
local RecoilCFrame = CFrame.Angles(math.rad((NewRecoil - LastRecoil)*Settings.UpRecoil),math.rad((NewRecoil - LastRecoil)*Settings.SideRecoil),0)
local CameraRotationCFrame = Camera.CFrame.Rotation
local RotationCFrame = RecoilCFrame * CameraRotationCFrame
local Position = Camera.CFrame.Position
Camera.CFrame = CFrame.new(Position.X,Position.Y,Position.Z) * RotationCFrame
For anyone else who encounters this issue I’d like to add that the up recoil will get reversed if you do use the method above, instead when adding up recoil use the Camera axis instead of global, otherwise if you look back with the global axis up recoil will go down, here is the updated script for that:
local SideRecoilCFrame = CFrame.Angles(0,math.rad(SideRecoil),0)
local UpRecoilCFrame = CFrame.Angles(math.rad(UpRecoil),0,0)
local CameraRotationCFrame = Camera.CFrame.Rotation
local RotationCFrame = SideRecoilCFrame * CameraRotationCFrame * UpRecoilCFrame
local Position = ThingNeeded.CFrame.Position
Camera.CFrame = CFrame.new(Position.X,Position.Y,Position.Z) * RotationCFrame
LastRecoil = NewRecoil