Custom crosshair sway effect

Greetings! :smiley:
I would like to create a sway effect for my custom crosshair, like when the player look around with his camera, the crosshair move slightly in the direction where the camera moves and when it stops, the crosshair comes to normal in the center of the screen.
I searched and try to do it, but it does not works.

This is what the cursor looks like :
image

Could you somehow, please, explain me how to do it? (tips will be appreciated)
Thanks! Looking forwards any answer.

2 Likes

try using userinputserive.touchmoved

i would use a spring module, and userInputService:GetMouseDelta() in a renderStepped loop
the spring module is pretty straightforward to use, and you can also change the dynamics of how it sways easily

Great! Any idea on how to do it? (parts of codes)

bump! still not found any way to create this effect…

Here’s what I use

local userInputService = game:GetService("UserInputService");
local runService = game:GetService("RunService");

local Frame = (script.Parent.MainGui)
local Crosshairpos = (scopeFrame.Position)

function Lorp(a, b, m)
	return a + (b - a) * m
end;

local swayX, swayY = 0, 0;
local SWAY_SPEED = (2);
function RenderStep(dt)
	userInputService.MouseIconEnabled = true
	local delta = userInputService:GetMouseDelta();	
	swayX = Lorp(swayX, delta.X * 2, dt * SWAY_SPEED)
	swayY = Lorp(swayY, delta.Y * -2, dt * SWAY_SPEED)
	Frame.Position = Crosshairpos + UDim2.fromOffset(swayX, swayY)
end;

runService.RenderStepped:Connect(RenderStep)

1 Like

Thanks! I modified your code to fit in mine and it works perfectly!

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