States

One of the primary ways that PCs and NPCs are managed in any game is through a ‘state’. These state values allow us to check if the character is resting, attacking, etc.

The Actor Core provides a list of states can are used by the Motion Controller and its motions. You can access these states or create custom states for your unique AI.

In the end, these states are simply made up of a name and an integer value. Both of these can be anything you want.

 

 

 

 

Stock States

The Motion Controller uses three stock states that should always exist:

Stance – The character’s ‘stance’ represents his state-of-mind. Think of it like his global state… traversing (default), melee combat, ranged combat, swimming, sneaking, etc. To see the stance values I use, you can look here.

Default Form – This value is used to help determine which animation plays for some motions. This allows us to set a default value that will be used when not other form value is set. To see the form values I use, you can look here.

Current Form – The current form value that determines what animations plays for some motions.

 

Stance vs Form

Think of “stance” as the overall character state-of-mind. Typically a character is simply walking or moving (traversal) or maybe they are in melee combat, in ranged combat, sneaking, etc. I use the stance variable in AI and motions to figure out the general state of the character.

“Form” is a more refined concept. If the character is in a “melee combat” stance, the “form” defines exactly how that stance will be animated… two handed sword, dual daggers, sword and shield, etc.

I change them when equipping weapons sets because that make sense to me. If you have your sword and shield in hand, you’re probably in a “melee combat” state-of-mind. Of course that isn’t always true, but it typically is.

Changing the stance in other motions totally makes sense. For example, if your character starts swimming it doesn’t really matter if they have a sword and shield in hand… they are swimming. Feel free to change the stance in motions, but sometimes you may need to reset the stance or form when you leave the motion. It really depends on what you’re creating.

I then use the stance variable to limit which motions can work. For example, if you’re not in a melee combat stance than even if you hit the ‘attack’ button I won’t try to run the Basic Melee Attack motion. If you’re not in a swimming stance, I won’t attempt to run any of the swimming motions.

In the end, stance and form are just integers. So, you can make them whatever you want. I try to reserve some values for me and the motion packs. However, you can set them for anything and any reason as long as it matches with my motions or custom motions you create.

 

Code

To access the states in code, you can do the following:


1
2
3
4
5
6
7
8
9
10
11
// Get a value
ActorCore lActorCore = gameObject.GetComponent(typeof(ActorCore));
int lValue = lActorCore.GetStateValue("Stance");

// Set a value
ActorCore lActorCore = gameObject.GetComponent(typeof(ActorCore));
int lValue = lActorCore.SetStateValue("Stance", 2);

// Remove a value
ActorCore lActorCore = gameObject.GetComponent(typeof(ActorCore));
int lValue = lActorCore.RemoveState("Stance");

To add a new state, simply use the ‘SetStateValue’ function. A state will be created if it doesn’t already exist.