Hello, I want to know how to animate a box. When using ProximityPrompt, the case opens with animation. I want to learn how to write such a script. I will be glad if I get help.
hmm, considering the case has an humanoid, you can animate it as you would for dummies:
local humanoid = script.Parent.Humanoid
local animator = Instance.new("Animator", humanoid)
local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://12676710902"
script.Parent.Triggered:Connect(function()
animator:LoadAnimation(anim):Play()
end)
(not using Humanoid:LoadAnimation()
since it’s deprecated.)
Don’t use Humanoids, use AnimationControllers.
In this case you’d need to rig your case to use Motor6Ds, the way a character’s joints are set up, I also recommend using an AnimationController over a Humanoid since the Humanoid gives it a load of properties you don’t want.
Assuming you’ve done all this already based on your video, the script should be fairly straightforward, loading the animation how you would with a character, and then playing it when the interaction has finished, that could look something like this
-- start of the script
local OpenAnimation = Animator:LoadAnimation(ANIMATION) -- load it
function PromptCompleted() -- when opened
OpenAnimation:Play()
end)
Now, one issue I had with this is that when the animation finished, it just reset back to it’s original state. I found that one way to solve this was to add a bunch of extra frames to the end of the animation, then in the script; task.wait()
a certain amount of time and anchor the entire model. This feels kinda hacky though and I’m sure there’s a better way
You could create a separate animation with 1 frame where the chest is opened and play it once the opening animation finishes.
So I did not understand what and how to write to me.