Skip to content

3 Miscellaneous Examples

Gabriel Dechichi edited this page Nov 7, 2022 · 1 revision

There are many other features to DMotion for which I haven't written documentation to yet :P. But they should feel relatively familiar to you now that you've went through the basics. Below is a short explanation of each example:

  • Blend Tree 1D

Path: All Samples/2 - State Machine/3 - BlendTree 1D/DMotion - State Machine - BlendTree1D.unity

This example will show you how to create 1D Blend Trees animation states. A Blend Tree 1D state is able to blend between N clips using a FloatParameter. Check out the Locomotion state in the 2.3_StateMachine_BlendTree1D.asset to see how it is setup. Remember you can change parameters at runtime via the State Machine editor to debug the state machine.

  • Enum Transitions

Path: All Samples/2 - State Machine/3 - BlendTree 1D/DMotion - State Machine - BlendTree1D.unity

Simple example showing how to use Enum Transitions to switch between 3 "idle modes". You only need to create the enum in code and then create the Enum Parameter and select the corresponding Enum type.

Enum parameters work just like int parameters under the hood, so in order to set enum parameters in code you can just use ref DynamicBuffer<IntParameter>.

  • Attached Objects

Path: All Samples/3 - Examples/Attached Objects/DMotion - Examples - Attached Objects.unity

This example shows how to attach objects, such as weapons, to animated skeletons. To achieve this you just need to either disable Optimize Game Objects in .fbx import settings (not recommended), or you can expose just the specific bones you need in Extra Transforms to Expose. Then just parent the object to the exposed bone.

image

  • Play One Shot

Path: Assets/Samples/DMotion/0.3.4/All Samples/3 - Examples/PlayOneShot/DMotion - Examples - Play One Shot.unity

This examples shows how to play a "one shot" animation. Those are animations that you want to play once, and then return back to the previous animation state being played. For instance, you may want to play an attack animation, and then blend back to the state machine. Of course, you could use a Bool Parameter for that, but then you would need to create one state and transitions for every attack animation a character could play, this is not ideal, so better to just play a clip outside the state machine and blend back to it.

It should feel very similar to the play clips through code example, take a look at PlayOneShotExampleSystem for the code.

  • Root Motion

Path: All Samples/3 - Examples/RootMotion/DMotion.Samples.Examples.RootMotion.asmdef

This example shows the different root motion modes, and how to transfer root motion to a parent game object (for the case where the SkeletalMesh is a child of the character object, for instance).

Note that for the LowPolyRobot_Automatic (With Owner), the motion is applied to the parent object (Owner), instead of the animated SkeletonMesh.

The "custom root motion" example (in CustomRootMotionSystem.cs) just reverts the delta movement value, so the character goes backwards. Custom root motion is useful for cases where you want the animation to control some of the motion but slightly alter it with gameplay code (i.e roll the character towards a specific direction), or when you have a custom character controller that needs to be in control of physics (so you want to apply root motion through it).