Animator and Animations

It is the user’s task to craft (Unity-) Animators (a.k.a. Animator Controllers) and provide Animations for his Units.

Of course, you do not need this for inanimate Units like e.g. Potions.

Animators

Animators in Unity are state machines. When you craft an Animator for TBE you do not need to add transitions except:

  • from Entry to Idle

  • if you wish to make a transition that happens unconditionally (e.g. a "cast-warmup" animation)

In Animator States, do not change the speed as this will eventually be overwritten by the engine at runtime.

Animations

Currently, Animations for Weapon Attacks need to emit an Event that must be called "AttackShoot". Otherwise, the unit will not shoot off its (auto)attack.

AttackShoot

Cast Animations do not need this.

Motion Mappers

The wish for a motion mapper may arise when you see something like this: idleMotionBad

Here I have a Unit from a package from the Asset store (Toon RTS Units by Polygon Blacksmith) and the idle motion is from a different package (RPG Character Mecanim Animation Pack by Explosive). Now this does not fit together: The sword goes through the head. Luckily, Explosive has a different idle motion:

idleMotionGood

Here I have used a Motion Mapper. The result is that the system plays different idle motions, depending on the equipped item.

To create a Motion Mapper

  1. extend the class UnitMotionMapper.

  2. add this extension class to your unit prefab.

  3. assign a motion hint to your item: swordItemMotionHint

Example

Motion Mapper Code:
The exact logic is up to you. You can come up with something even more clever ;-)
public class HumanMotionMapper : UnitMotionMapper {

    private RtUnitBhv unit;

    private void UnitIsInitialized() {
        unit = GetComponentInParent<RtUnitBhv>();
    }

    private readonly List<string> mapped = new() {"Bow", "Sword", "Staff"};

    public override string DoMap(string stateName) {
        var motionHint = unit.abilities.Inventories.EquippedMotionHintProperty.CurrentValue;

        if (string.IsNullOrEmpty(motionHint)) {
            // no item with a motion hint is currently equipped.
            return stateName;
        }

        if (stateName.Equals(Tbe.MotionName.Of(Motion.Cast))) {
            // we do not have special animations for Cast.
            return stateName;
        }

        if (motionHint.Equals("Sword") && stateName.Equals(Tbe.MotionName.Of(Motion.Attack))) {
            // special: we have 2 different sword attack animations.
            return "SwordAttack" + Random.Range(0, 2);
        }

        // all other mapped motions:
        if (mapped.Contains(motionHint)) {
            return motionHint + stateName;
        }


        return stateName;

    }
}
Animation Controller (fitting to that Code):

exampleAnimationController

you do not have to have motions for all states. If you do not have an Animation that fits e.g. SwordDie, you can use your normal Die Animation in the SwordDie state. Think of the Unity Animation Controller as an additional mapper.