Hello , I’m currently working on a battle royale game and i want to make parts shake when you hit them with your pickaxe (just like in strucid).
I tried moving it by using CFrame but that was unsmooth. How can I make it shake smoothly? Any help would be very appreciated!
Tweening is a good option and allows for a smoother movement.
Another choice is animating the model, basically parent the model to a hitbox brick which moves the entire model. Then animate the hitbox as a shaky movement.
Edit: Or make completely custom animations for all the things that can be destroyed. (idk but may lower load times and make it more laggy)
If you ever want to move parts smoothly in your game, just use TweenService
, like @3rdhoan123 said.
e.g.:
TweenService = game:GetService("TweenService")
function ShakePart(part)
local cycleDuration = 0.1
local totalDuration = 0.5
local volatility = 1
local savedPosition = part.Position
local tweeninfo = TweenInfo.new(
cycleDuration,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
for i = 0, totalDuration - cycleDuration, cycleDuration do
local tween = TweenService:Create(
part,
tweeninfo,
{Position = savedPosition + Vector3.new(math.random(),math.random(),math.random()).Unit * volatility}
)
tween:Play()
tween.Completed:Wait()
end
TweenService:Create(
part,
tweeninfo,
{Position = savedPosition}
):Play()
end
You might also want to play a sound somewhere at the beginning for more pizzazz, but that’s up to you.
There seems to be an error on the 31 , 36 lines;
Could we see the code you’re using to make contact with the model to animate it?
That would help with finding the issue.
I added a ‘,’ at the 31th line and now it seems to be working.
Here is the code:
TweenService = game:GetService("TweenService")
function ShakePart(part)
local cycleDuration = 0.1
local totalDuration = 0.5
local volatility = 1
local savedPosition = part.Position
local tweeninfo = TweenInfo.new(
cycleDuration,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
for i = 0, totalDuration - cycleDuration, cycleDuration do
local tween = TweenService:Create(
part,
tweeninfo,
{Position = savedPosition + Vector3.new(math.random(),math.random(),math.random()).Unit * volatility}
)
tween:Play()
tween.Completed:Wait()
end
TweenService:Create(
part,
tweeninfo,
{Position = savedPosition}
):Play()
end
while true do
wait(0.5)
ShakePart(script.Parent)
end
Already done it. Ty for trying to help me tho
Your welcome, glad to help! Good luck on your project btw