Original Source
Here's another tutorial for you guys. This one shows you how to make animations play based on some event (like a mouse click). As with our other tutorial, let us know if you have any comments!
This tutorial is for Beta 3.2.
-Chris, Asylum Programming Team
--------------------------------------------------------------------------------------------------------------------------------
This tutorial was also done using the Black Skull Camp Tech Demo.
To have additional user triggered animations we have to set up a new animationin the avatar's .cs file in the OnPrepareForUse() method like so:
AnimationSet.ConfigureAnimations(
new Animation(AvatarCommands.Action2, "AnimationName", animSpeed, null, true)
);
There are currently AvatarCommands.Action 1 through 9, Action1 is triggered by the left mouse button and is used for the primary attack. "AnimationName" should be replaced with the name of the animation you want to play, and that boolean on the end signifies wether or not the animation can loop. Obviously if we don't want a looping animation, set it to false.
Now that we've set up an Action2 animation we can head on over to the mouse handler at Demo Assets\Actors\AvatarInputController.cs and set the right mouse button to trigger the new animation. For the tech demos Realmware has the right moues button do a few things, we'll have to comment all that out, or I guess delete it if that's how you roll.
For our puposes we'll comment out lines 157-163, 206-214 and 264-300. Now we have freed up the right mouse button from doing anything while you're controlling an avatar. So what's left to do is have the right mouse button trigger our animation!
if (IsMouseOwned && (inputEventArgs.Key == Key.MouseButtonRight))
{
if (inputEventArgs.WasPressed)
{
if (!_targetObject.HasActivity(AvatarCommands.Action2 ))
{
_targetObject.ExecuteUserCommand(AvatarCommands.Ac tion2, null);
inputEventArgs.HandledBy = this;
}
}
else if (!inputEventArgs.IsMouseButtonPressed(MouseButton. Right))
{
_targetObject.ExecuteUserStopCommand(AvatarCommand s.Action2);
}
}
The else if is what stops the animation from looping when you release the right mouse button. And now you may give yourself a pat on the back. Maybe even a cookie if you're hungry.
-Tashi Duane, Asylum Project