How can I make UI shake?

Hello,

I was looking to make a simple UI shake effect, but I wasn’t sure how to go about it.

I could just make a bunch of tweens to move it around a small space, giving it the effect, but it would probably be inefficient and wouldn’t have the effect I’m trying to achieve.

Help is appreciated.

2 Likes

can uou pls show an example of the shake ur tryna get

2 Likes

I dont have a great example of it, besides what I just screen recorded.

Sorry for the poor clip, it’s the best I have.

2 Likes

Here’s a rough code on how you would normally shake the UI:

local originalPosition = script.Parent.Position

local intensity = 15
local speed = .05

while true do --you probably shouldn't use a loop, im just using this as an example
	script.Parent.Position = originalPosition + UDim2.fromOffset(math.random(-intensity, intensity), math.random(-intensity, intensity))
    -- ^^^ you can also tween this instead for a more fluid feel

	task.wait(speed)
end

script.Parent.Position = originalPosition --after we're done we set it back to the original position, of course in this example we're never done, but if you plan to stop it you must do this

Hopefully it gives the results you want!

8 Likes

My take on this:

local RunServ = game:GetService("RunService")
local Pos = script.Parent.Position

RunServ.RenderStepped:Connect(function(dt)
	local BobbleX = (math.cos(os.clock() * 20) * 0.01) -- Increase 20 for an intense shake. Increase decimal number for how far it goes.
	local BobbleY = math.abs(math.sin(os.clock() * 30) * 0.01) -- Increase 30 for an intense shake. Increase decimal number for how it goes.
	script.Parent.Position = Pos + UDim2.new(BobbleX,0,BobbleY,0) -- Adding pos to the elements, so we can keep the UDIM2 relative to its original position.
end)
20 Likes

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