I’m trying to make a sway viewmodel like the deadline but i dont know how i would do it, i already tried with math.clamp but it dont look works properly
Example:
my current code:
-- Sway_Multiplifiers
local multX = 1
local multY = 0.2
local multZ = 2
-- Sway_Function
function SwayUpdate()
local rotation = Camera.CFrame:toObjectSpace(lastCameraCF)
local x,y,z = rotation:ToOrientation()
swayOffset = swayOffset:Lerp(CFrame.Angles(math.sin(x)*multX,math.sin(y)*multY,math.sin(z)*multZ), 0.1)
Camera:FindFirstChild(Weapon_Name).CameraBone.CFrame = Camera:FindFirstChild(Weapon_Name).CameraBone.CFrame * swayOffset
end
without clamp result
with clamp result:
code with clamp:
-- Sway_Multiplifiers
local multX = 1
local multY = 0.2
local multZ = 2
-- Sway_Function
function SwayUpdate()
local rotation = Camera.CFrame:toObjectSpace(lastCameraCF)
local x,y,z = rotation:ToOrientation()
local maxtilt = game:GetService("ReplicatedStorage").NUMERO.Value
local ValueX = math.clamp(x, -maxtilt,maxtilt)
local ValueY = math.clamp(y, -maxtilt,maxtilt)
local ValueZ = math.clamp(z, -maxtilt,maxtilt)
swayOffset = swayOffset:Lerp(CFrame.Angles(math.sin(ValueX)*multX,math.sin(ValueY)*multY,math.sin(ValueZ)*multZ), 0.1)
Camera:FindFirstChild(Weapon_Name).CameraBone.CFrame = Camera:FindFirstChild(Weapon_Name).CameraBone.CFrame * swayOffset
end