i can solve a thing via classical (scripting way) but unable to solve playmaker way.
situation
i have a character, with two collider spheres in heirarchy ( spine / face ) setup via mechanim. character kept looping idle animations (blendtree).when user clicks on collider sphere, it plays certain animation as reaction (like talking tom game scenario)
classical solution via scripting
1- apply mono behaviour to both colliders, which notice "OnMouseDown". it has a delegate in it to link with main script on root of character (animator controller)
2- animator_controlScript is on root, it references colliders at startup and use delegate function to toggle transitional switches ( variables of animation controller interface ).
sample collider code
public class ColliderReaction : MonoBehaviour {
// Event Handler
public delegate void OnCharacterClicked(GameObject g);
public event OnCharacterClicked OnCharacterClickedHandler;
void OnMouseDown () {
//Debug.Log("what the heck is happening here");
Debug.Log(this.gameObject);
OnCharacterClickedHandler(this.gameObject);
}
}
sample character root animator control script
public class Goli_ControlScript : MonoBehaviour {
public GameObject collFace;
public GameObject collSpine;
private Animator anim; // a reference to the animator on the character
private AnimatorStateInfo currentBaseState; // a reference to the current state of the animator, used for base layer
static int idleGroup = Animator.StringToHash ("Base Layer.idleGroup");
static int act1 = Animator.StringToHash("Base Layer.Interactive_SwipeFaceSlap");
static int act2 = Animator.StringToHash("Base Layer.Interactive_PunchBelly");
// Use this for initialization
void Start () {
anim = GetComponent<Animator>();
// setup sphere colliders for reactions
ColliderReaction sc1 = collFaceL.GetComponent<ColliderReaction>();
sc1.OnCharacterClickedHandler += charClickedHandler;
ColliderReaction sc2 = collFaceR.GetComponent<ColliderReaction>();
sc2.OnCharacterClickedHandler += charClickedHandler;
}
void charClickedHandler(GameObject g) {
if (g == collSpine) {
anim.SetBool("atSwipePunch", true);
}
else if (g == collFace) {
anim.SetBool("atSwipeFace", true);
}
}
void Update () {
currentBaseState = anim.GetCurrentAnimatorStateInfo(0);
if (anim.IsInTransition(0) && inTransition == false && currentBaseState.nameHash == idleGroup) {
Debug.Log("starting transition..");
resetAnimParams();
}
else if (anim.IsInTransition(0) == false && inTransition == true && currentBaseState.nameHash == idleGroup){
Debug.Log("ending transition..");
inTransition = false;
}
}
void resetAnimParams() {
inTransition = true;
currentBaseState = anim.GetCurrentAnimatorStateInfo(0);
anim.SetBool("atSwipeFace", false);
anim.SetBool("atSwipePunch", false);
anim.SetFloat("IdleRand",Random.Range(0f,1f));
Debug.Log("Duration:" + currentBaseState.length);
}
}
at this point, my idles logic is working (more smartly) in playmaker. i am slightly confused about how to proceed.
Q. how to get "OnMouseDownClick" on colliders
Q. how to call main fsm on root(shown in image) from fsm (at colliders)
General Questions
Q. is it smart idea to do everything in one FSM or using multiple fsm's is OK?
Q. how to call state of one fsm from another fsm?
i really appriciate if someone outline general steps / recommend psudo steps
huge thanks in advance
regards,lala