i am making a gun system and am trying to recreate a kind of gun sway used in Deadline, an fps game on roblox. this kind of gun sway sort of adds the camera movement to a value permanently with limits instead of just having the gun sway with camera movement, if that makes sense.
here is the code of what i have come up with so far:
local mouseVector = InputService:GetMouseDelta()/100
sysValues.cameraPositionX += mouseVector.X/5
sysValues.cameraPositionY -= mouseVector.Y/5
local cposXLimit = sysValues.cameraPositionLimit
local cposYLimit = sysValues.cameraPositionLimit
if sysValues.cameraPositionX > cposXLimit then
sysValues.cameraPositionX = cposXLimit-0.002
elseif sysValues.cameraPositionX < -cposXLimit then
sysValues.cameraPositionX = -cposXLimit+0.002
end
if sysValues.cameraPositionY > cposYLimit then
sysValues.cameraPositionY = cposYLimit-0.002
elseif sysValues.cameraPositionY < -cposYLimit then
sysValues.cameraPositionY = -cposYLimit+0.002
end
and i just add these cameraPosition values to the cframe of the viewmodel.
this works but has a problem. the movement is limited to a box shape, which feels unnatural.
and i want it to be limited to a circle, like this
i have tried some simple stuff with the values but i am not great at math, so i can not come up with a solution. any help is appreciated. thank you