Weapon sway point towards barrel/mouse

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

c482da5cad9441ebc561fa3494d0ae59

scpab2 sway for reference

External Media

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.

This doesn’t have any relevancy to my issue.

I know how to make frameworks i’ve made several others before, im just a little stuck on some swaying shenanigans

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

not sure if i worded it wrong but this still does not relate to my issue.

1 Like

Have you tried lerping the sway’s CFrame with the camera’s middle point’s? Maybe using ScreenPointToRay to get the mouse’s position in the 3D space.

1 Like

shoot, no idea why i didn’t think of this LOL…

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.