How To Animate A Dummy In Roblox Studio
The second way of using animations is to play them in response to a character'south action in-game: for instance, if a player picks upwards an detail, or takes damage.
In this side by side script, whenever a player presses a push button, a shock animation will play and paralyze them until the animation finishes.
Setup
The balance of this course uses a pre-made model that includes a ProxmityPrompt. Players can walk upwards to a push button and press it to activate an consequence.
-
Download the Stupor Button model and insert it into Studio.
Models tin can be added into your Inventory to be used in any game.
-
In a browser, open up the model page, click the Get button. This adds the model into your inventory.
-
In Studio, go to the View tab and click on the Toolbox.
-
In the Toolbox window, click on the Inventory button. Then, make sure the dropdown is on My Models.
-
Select the Shock Button model to add together information technology into the game.
-
-
In StarterPlayer > StarterPlayerScripts, create a local script named PlayShockAnimation.
-
The lawmaking below calls a function named
onShockTrigger
when the proximity prompt is activated. Copy it into your script.local Players = game:GetService("Players") local player = Players.LocalPlayer local character = player.Grapheme if non character or non character.Parent and then character = thespian.CharacterAdded:Expect() end local humanoid = graphic symbol:WaitForChild("Humanoid") local Animator = humanoid:WaitForChild("Animator") local shockButton = workspace.ShockButton.Push button local proximityPrompt = shockButton.ProximityPrompt local shockParticle = shockButton.ExplosionParticle local office onShockTrigger(role player) shockParticle:Emit(100) end proximityPrompt.Triggered:Connect(onShockTrigger)
Create and Load an Animation
Animations that the actor uses are stored on the player'south Animator object. To play the daze blitheness, a new animation track volition need to be loaded onto the Animator object when they join the game.
-
Above
onShockTrigger
, create a new Blitheness case namedshockAnimation
. And then, set theAnimationID
of that to the desired animation. Use the ID in the code box if needed.local shockButton = game.Workspace.ShockButton.Button local proximityPrompt = shockButton.ProximityPrompt local shockParticle = shockButton.ExplosionParticle local shockAnimation = Instance.new("Animation") shockAnimation.AnimationId = "rbxassetid://3716468774" local function onShockTrigger(player) end
-
Create a new variable named
shockAnimationTrack
. On the player's Animator, callLoadAnimation
, passing in the previously created animation.local shockAnimation = Instance.new("Animation") shockAnimation.AnimationId = "rbxassetid://3716468774" local shockAnimationTrack = Animator:LoadAnimation(shockAnimation)
-
With the new animation loaded, modify some of the rails's properties.
- Set the AnimationPriority to
Activity
- Ensures the blitheness overrides any current animations playing. - Prepare Looped to
false
and then the animation doesn't repeat.
local shockAnimation = Instance.new("Blitheness") shockAnimation.AnimationId = "rbxassetid://3716468774" local shockAnimationTrack = Animator:LoadAnimation(shockAnimation) shockAnimationTrack.Priority = Enum.AnimationPriority.Action shockAnimationTrack.Looped = imitation
- Set the AnimationPriority to
Play the Animation
Whenever someone triggers the ProximityPrompt on the button, it'll play an blitheness and temporarily freeze that thespian.
-
Find the
onShockTrigger
office. On theshockAnimationTrack
, call thePlay
role.local function onShockTrigger(player) shockParticle:Emit(100) shockAnimationTrack:Play() stop
-
To prevent the role player from moving while the animation plays, modify the humanoid's
WalkSpeed
belongings to 0.local function onShockTrigger(role player) shockParticle:Emit(100) shockAnimationTrack:Play() humanoid.WalkSpeed = 0 end
Using Animations with Events
Merely how parts take Touched events, animations have events such as AnimationTrack.Stopped
. For the script, once the animation finishes, you'll restore the player'southward move speed.
-
Access the
Stopped
event for the animation track using the dot operator, and so call theWait
office. This pauses the code until that animation finishes.local function onShockTrigger(player) shockParticle:Emit(100) shockAnimationTrack:Play() humanoid.WalkSpeed = 0 shockAnimationTrack.Stopped:Await() end
-
Return the player's walk speed to 16, the default for Roblox players.
local part onShockTrigger(player) shockParticle:Emit(100) shockAnimationTrack:Play() humanoid.WalkSpeed = 0 shockAnimationTrack.Stopped:Wait() humanoid.WalkSpeed = sixteen end
-
Test the game by walking upwards the part and press E to go a shock.
The framework in this script tin be hands adapted to unlike gameplay situations. For instance, try playing a special animation whenever a player touches a trap office, or whenever a team wins a game round.
Source: https://developer.roblox.com/en-us/onboarding/scripting-avatar-animations/2
Posted by: sullivanwhinged.blogspot.com
0 Response to "How To Animate A Dummy In Roblox Studio"
Post a Comment