Animation Events on Default Animations

How would I go about adding animation events to a default animation? I’m trying to add a footstep event for the walking animation. I exported the default animation and added the animation events at the right keyframes, but cant quite figure out the scripting part. Thank you in advance. :slight_smile:

5 Likes

To add animation events to a default animation, you’ll need to use a script to trigger the footstep events at the right keyframes. Here’s a step-by-step guide to help you achieve this:

  1. Create the Animation and Add Events:
  • First, create the walking animation for your character, including the footstep animation events at the desired keyframes. You can do this in Roblox Studio’s Animation Editor.
  • Place the animation in a folder within the Workspace or a Model in your game. Make sure you remember the animation’s name.
  1. Create a Script:
  • In Roblox Studio, go to the Explorer window and create a new Script under the location where you want the animation to be triggered. It could be under StarterPlayerScripts, for example.
  1. Write the Script:
  • Open the Script and use the Instance.new() function to create a new Animation object, specifying the path to your animation within the game’s workspace.
  • Use the LoadAnimation() method to load the animation from the path you provided.
  • Create a function that will be called when the animation plays.
  • Use the Animation:GetMarkerReachedSignal() method to get a signal for when an animation event marker is reached.
  • Connect the signal to a function that will handle the footstep event, and inside that function, you can perform any action you want, such as playing a sound or triggering a particle effect.

Here’s a sample script to give you an idea of how to approach this:

local animationId = "rbxassetid://YOUR_ANIMATION_ID" -- Replace this with the asset ID of your animation

local function onMarkerReached(markerName)
    if markerName == "Footstep" then
        -- Do something, e.g., play a sound or trigger a particle effect
        print("Footstep event triggered!")
    end
end

local humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
local animation = Instance.new("Animation")
animation.AnimationId = animationId
local loadedAnimation = humanoid:LoadAnimation(animation)

loadedAnimation:GetMarkerReachedSignal():Connect(onMarkerReached)
loadedAnimation:Play()

Make sure to replace "rbxassetid://YOUR_ANIMATION_ID" with the actual asset ID of your walking animation.

OBS: this script assumes you want to trigger the footstep events for the LocalPlayer’s character. If you want to do this for other players or NPCs, you will need to adjust the code accordingly.

I edited the Animate script, and in the playAnimation function I added (on line 267)

currentAnimTrack:GetMarkerReachedSignal("Footstep"):Connect(function()
	print("footstep")
end)

there is definitely room for improvement here, for example adding a new variable into the animate script for the signal, but I don’t need to do all that work for my current purposes.

1 Like

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