I’m working on weapon sway for a small little practice framework and i want it to seem similar to a game named scp anomaly breach 2, which in scp anomaly breach 2 the sway angles towards the mouse or moreso the barrel. but i dont know how to make the sway point towards the mouse.
i’ve tried some stuff with cframe.lookat() but that ended up just giving catastrophic results.
mouse.Move:Connect(function()
local mouseDelta = UIS:GetMouseDelta()
if viewmodel then
local firePoint:Attachment = viewmodel:WaitForChild(tool.Name):WaitForChild("Barrel"):FindFirstChildWhichIsA("Attachment")
game:GetService("TweenService"):Create(
localOffsets.mouseDeltaOffset,
TweenInfo.new(.4,Enum.EasingStyle.Sine),
{Value = CFrame.new(math.clamp(mouseDelta.x/40,-.5,.5), -math.clamp(mouseDelta.y/40,-.5,.5), 0)}
):Play()
end
end)
--further down into a renderstep with irrelevant things removed
viewmodel.PrimaryPart.CFrame *= localOffsets.mouseDeltaOffset.Value
I would not recommend trying to do this on your own unless you know exactly what you’re doing. Use the tutorial I did. It works and it works phenomenal.
local mult = 1
local swayOffset = CFrame.new()
local lastCameraCF = workspace.CurrentCamera.CFrame
function renderloop() --bind this camera render loop
local rotation = workspace.CurrentCamera.CFrame:toObjectSpace(lastCameraCF) --get cframe delta.
local x,y,z = rotation:ToOrientation() --I'm sure there are better ways to get rotation but this will work for now.
swayOffset = swayOffset:Lerp(CFrame.Angles(math.sin(x)*mult,math.sin(y)*mult,0), 0.1) --calculate the sway using SIN
gun.CFrame = gun.CFrame * swayOffset --apply the sway
lastCameraCF = workspace.CurrentCamera.CFrame --update the last cframe
end