I want to create a recoil system but I need to figure out how to offset the camera with rotation.
Something like CS:GO or Rust.
I dont know what you mean.
local Cam = game.Workspace
cam.CameraType = Enum.CameraType.Scriptable
cam.CameraSubject = workspace.Part
part.Rotation += 50
Something like this?
So, which part is about rotating a camera with a number without it stacking up?
I’m trying to make a recoil system like CSGO (where the camera goes back down after a bit)
and I don’t know how to do it.
I would suggest using springs for this, BlackShibe’s fps framework 2020 uses his spring module
Look through that when he makes gun sway, the usage for the spring module is explained in the article above.
I would suggest making a RenderStepped bind and do
local Recoil = CamSpring:update(dt)--<<deltatime is the only thing passed into RenderStepped
game.Workspace.CurrentCamera.CFrame *= CFrame.Angles(Recoil.X, Recoil.Y, Recoil.Z)
Couldnt you just play an animation instead of offset the camera?
No, I want the camera to move without animations since animations are only set in one way it won’t be the same as making it procedurally.
Here is a function I made for you that works for models, baseparts or any PVInstance (Have a location in the world) and also respects the new pivot feature!
local function offsetObjectRotation(object : PVInstance | Camera, rotationOffsetXYZ : Vector3)
if object:IsA("PVInstance") then
local oldCFrame = object:GetPivot()
local newCFrame = oldCFrame * CFrame.Angles(rotationOffsetXYZ.X, rotationOffsetXYZ.Y, rotationOffsetXYZ.Z)
object:PivotTo(newCFrame)
elseif object:IsA("Camera") then
local oldCFrame = object.CFrame
local newCFrame = oldCFrame * CFrame.Angles(rotationOffsetXYZ.X, rotationOffsetXYZ.Y, rotationOffsetXYZ.Z)
object.CFrame = newCFrame
else
error("Cannot rotate the object of class name "..object.ClassName)
end
end
Here is an example on how to use it
The following code offset the rotation of it’s parent part by 45 degrees along the local X axis of the object.
offsetObjectRotation(script.Parent, Vector3.new(math.rad(45), 0, 0))
Before running the example code
After running the example code
Enjoy!
That’s cool but, how would it work on the camera?
The camera doesn’t have a pivot unless I stand corrected
local camera = workspace.CurrentCamera
camera .CameraType = Enum.CameraType.Scriptable
function Recoil()
camera.CFrame = camera.CFrame:ToWorldSpace(CFrame.Angles(math.rad(0.05), math.rad(0.1), 0)
end
You will prob need to change values since i put random numbers, put thats how I would do some recoil
If you want it to be smooth recoil instead of jittery recoil springs would be the way to go.
Edit: they require a bit more implementation but i think its worth it
offsetObjectRotation(camera, Vector3.new(angleX, angleY, angleZ))
If you need more information, let me know!
Ohhhh okay thanks I’ll try that out
As I thought, the camera doesn’t have a pivot
15:10:45.118 GetPivot is not a valid member of Camera “Workspace.Camera” - Client - Framework:314
15:10:45.118 Stack Begin - Studio
15:10:45.118 Script ‘Workspace.TruestBlu.Framework’, Line 314 - function offsetObjectRotation - Studio - Framework:314
15:10:45.118 Script ‘Workspace.TruestBlu.Framework’, Line 353 - Studio - Framework:353
15:10:45.119 Stack End - Studio
I think thats because camera isnt a BasePart
Alright, let me fix that, didn’t know that the camera doesn’t have a PVInstance
I’ve replaced them with cframe so hopefully it’ll work
Okay so I want the camera to move correspondingly to a number, lets say hmmm it’s 4. When that number goes down I also want the camera to move down with it and vice versa.