playMaker

Author Topic: last time, request for help  (Read 2234 times)

lalamax3d

  • Playmaker Newbie
  • *
  • Posts: 12
last time, request for help
« on: August 11, 2013, 01:15:14 PM »
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
Code: [Select]
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
Code: [Select]
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

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: last time, request for help
« Reply #1 on: August 14, 2013, 08:57:53 AM »
Hi,

--  OnMouseDown() within playmaker is done via the global system event "MOUSE DOWN". that's how you are going to know that the mouse is down on this gameobject.

-- Calling other fsm ( or root) can be done in two ways

-- either you have a reference of the fsm and you send an event just to that fsm.

-- or you fire a global event. this works if you have one player. for ennemies and when you more than one instance running this won't work.


In general, it's a very good idea to spread logic in several fsm. And sometime you'll see that there is no other alternatives actually. Simply because for a given FSM, there can be only one active state at a time. So it's very common to require 2 3 fsm for a feature to operate, all three fsm either sharing variables or fire event to one another.

what do you mean "call State", do you mean go to a particular state? if so, simply have a gloval event on that state and send that event to that fsm, and it will de facto be on that state,
 

bye,

Jean

lalamax3d

  • Playmaker Newbie
  • *
  • Posts: 12
Re: last time, request for help
« Reply #2 on: August 14, 2013, 09:21:39 AM »
Thanks. It's very helpful...