Best way to make an object shake effect

Pretty self explanatory so going to keep this short, what is the best, yet fairly efficient way of making an <1 second object shake effect on an anchored part?

This would take place after it was hit by a tool. so nothing massive.

2 Likes

the simplest would probably be to save its original position, and then call a simple loop to randomly set that object, or the primary part + or - .05 or .1 studs

3 Likes

Use cframe and two for loops.

Part = script.Parent

for i=0,10 do wait()
	Part.CFrame = Part.CFrame.new(.1,0,0)
end

for i=0,10 do wait()
	Part.CFrame = Part.CFrame.new(-.1,0,0)
end

You could also use tween service if you want to go the extra mile.
https://developer.roblox.com/en-us/api-reference/function/TweenService/Create

3 Likes

Potentially, but loops boring ! :stuck_out_tongue: , is there anything more interesting or some neglected feature you know about?

2 Likes

if you so desperately dont want loops, just use tweenservice with the bounce easingstyle

5 Likes
local TweenService = game:GetService("TweenService")
 
local tweenInfo = TweenInfo.new(
	2, -- Time
	Enum.EasingStyle.Linear, -- EasingStyle
	Enum.EasingDirection.Out, -- EasingDirection
	1, -- RepeatCount (when less than zero the tween will loop indefinitely)
	true, -- Reverses (tween will reverse once reaching it's goal)
	0 -- DelayTime
)

goal = {}
goal.CFrame = part.CFrame*CFrame.new(1,0,0)

local tween = TweenService:Create(part, tweenInfo, goal)
 
tween:Play()

:cake:

5 Likes

forgot about bounce and elastic transition styles thx!, kk ima play around with an elaborated form of that!

Thanks, but i know how to use tween service lol, i was merely interested in if there were any particularly exotic methods i could use!

1 Like

I know I am a bit late, but I was curious. I am learning scripting. And will it shake every second with this script?

Also is the (1,0,0) part in the script the amount of studs it is allowed to move?

Nope it won’t but if you want to do so using TweenService, just set the RepeatCount to -1 and the DelayTime to 1 (since it’s gonna repeat every second)