playMaker

Author Topic: PlaymakerAnimatorProxy -> ApplyRootMotion  (Read 14254 times)

pietwelve

  • Junior Playmaker
  • **
  • Posts: 70
PlaymakerAnimatorProxy -> ApplyRootMotion
« on: April 06, 2013, 07:31:24 PM »
Hi,
I try to redo the UnityMecanimTutorial using Playmaker instead of the given "BotControlScript".
In order to use the "SetAnimatorFloat" Action (eg to set the speed or direction) i have to apply the "PlaymakerAnimatorProxy" Script.
But then My Animator Component switch to "Apply Root Motion : handled by script".
So my Bot Walk on Spot
Is there a way to avoid that and keep "ApplyRootMotion : On" ?
I have tried the "SetAnimatorApplyRootMotion" Action but it doesn't change anything (and doesn't get green when play?) ...
Thanks for your help
« Last Edit: April 06, 2013, 09:29:24 PM by pietwelve »

Pino of DFT Games

  • Playmaker Newbie
  • *
  • Posts: 3
    • DFT Games Official Website
Re: PlaymakerAnimatorProxy -> ApplyRootMotion
« Reply #1 on: April 06, 2013, 09:35:13 PM »
Same here... Even adding the "Set Animator Apply Root Motion" to the fsm the result is unchanged  :(

Anyway, I've modified the proxy as follows and it works fine:

Code: [Select]
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;

[RequireComponent(typeof(Animator))]
[RequireComponent(typeof(PlayMakerFSM))]
public class PlayMakerAnimatorProxy : MonoBehaviour {

public event Action OnAnimatorMoveEvent;

public event Action<int> OnAnimatorIKEvent;

private Animator anim = null;

void Start()
{
anim = gameObject.GetComponent<Animator>();
}

void OnAnimatorMove()
{
if( OnAnimatorMoveEvent != null )
{
OnAnimatorMoveEvent();
transform.position = anim.rootPosition;
transform.rotation = anim.rootRotation;
}
}

void OnAnimatorIK(int layerIndex)
{
if( OnAnimatorIKEvent != null )
{
OnAnimatorIKEvent(layerIndex);
}
}
}

Rahuzin

  • Playmaker Newbie
  • *
  • Posts: 3
Re: PlaymakerAnimatorProxy -> ApplyRootMotion
« Reply #2 on: April 07, 2013, 06:35:34 AM »
I have the same problem that pietwelve described. I want to control the root using animation. I hope someone will be able to solve this problem. Sorry for my English.
Thanks.

Pino of DFT Games

  • Playmaker Newbie
  • *
  • Posts: 3
    • DFT Games Official Website
Re: PlaymakerAnimatorProxy -> ApplyRootMotion
« Reply #3 on: April 07, 2013, 08:32:12 AM »
I have the same problem that pietwelve described. I want to control the root using animation. I hope someone will be able to solve this problem. Sorry for my English.
Thanks.

Hi, did you try my fix? That works for me.

Rahuzin

  • Playmaker Newbie
  • *
  • Posts: 3
Re: PlaymakerAnimatorProxy -> ApplyRootMotion
« Reply #4 on: April 07, 2013, 09:02:20 AM »
Hi, PinoEire. I just tried to do so. And seems it worked. So thank you very much, your solution really helped.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: PlaymakerAnimatorProxy -> ApplyRootMotion
« Reply #5 on: April 08, 2013, 01:47:21 AM »
Hi,

 Could you point to me this exact tutorial? the modifications you did to the proxy may works, but that's not supposed to be the way to do it, as this proxy is only here to forward events to the actions, so I would like to get to the bottom of this, cause I am sure it's only a matter of finding the right set of actions to perform this properly.

bye,

 Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: PlaymakerAnimatorProxy -> ApplyRootMotion
« Reply #6 on: April 08, 2013, 04:39:38 AM »
Hi,

 Ok, I found the problem and it's not cool actually. Unity detects when I use the specific OnAnimatorMove() method, and then assume that I will do everything and turn off all the internal root motion system applied to the "characterController" component which means you loose both the positionning AND the collision/stairs and all that... and for odd reasons, telling animator to applyMotionRoot do not work at all even if you set it at runtime, it's nothing to do with PlayMaker, it's by design.

 I think it's very bad, cause here in most case we only want to set and get animator variables, and we are heavily penalized by doing so within the OnAnimatorMove() method, so I removed that dependancy all together ( cause in the first place, I am not seeing any differences yet between OnAnimatorMove() and OnUpdate(), I am sure there are, but I fail to find infos on when exactly it's required to use OnAnimatorMove() )

so, please update the package from the wiki, it contains a new version of the custom actions, AND a scene, the animator controller one, where the player can move around, jump ( when running only) and say hello when you fire. Tell me if that works for you, for me, I recovered all the wonders of characterController and do not have to apply the root motion manually ( since It's ticked in the animator behavior)

https://hutonggames.fogbugz.com/default.asp?W1031

bye,

 Jean
« Last Edit: April 15, 2013, 06:51:14 AM by jeanfabre »

pietwelve

  • Junior Playmaker
  • **
  • Posts: 70
Re: PlaymakerAnimatorProxy -> ApplyRootMotion
« Reply #7 on: April 08, 2013, 05:05:43 PM »
Thanks PinoEire for your quick answer, (sorry for my late answer)
Thanks Jean for the new Package.
After a quick test it seems to work fine.  :D
I'll look deeper into that in the next few days.
(please excuse my poor english  ;) )

Pino of DFT Games

  • Playmaker Newbie
  • *
  • Posts: 3
    • DFT Games Official Website
Re: PlaymakerAnimatorProxy -> ApplyRootMotion
« Reply #8 on: April 09, 2013, 01:12:57 PM »
Sorry for the delay, I didn't get notified of the answers :/

Ok, I found the problem and it's not cool actually. Unity detects when I use the specific OnAnimatorMove() method, and then assume that I will do everything and turn off all the internal root motion system applied to the "characterController" component which means you loose both the positionning AND the collision/stairs and all that... and for odd reasons, telling animator to applyMotionRoot do not work at all even if you set it at runtime, it's nothing to do with PlayMaker, it's by design.

That's indeed correct: I don't know why they do that, but it's been a well known issue since the introduction of Mecanim. The solution I posted is indeed the one suggested by Unity  ;)

so, please find a package attached here, it contains a modified version of the custom actions, AND a scene, the animator controller one, where the player can move around, jump ( when running only) and say hello when you fire. Tell me if that works for you, for me, I recovered all the wonders of characterController and do not have to apply the root motion manually ( since It's ticked in the animator behavior)

Great! Giving it a try right away  :D

Cheers,
Pino

Rahuzin

  • Playmaker Newbie
  • *
  • Posts: 3
Re: PlaymakerAnimatorProxy -> ApplyRootMotion
« Reply #9 on: April 16, 2013, 02:24:45 PM »
I'm not sure may I write about it here. But I had a problem. Solutions provided here helped me a lot and now I have a character controlled by the animation. But sometimes my character ignores the collision. If I correctly understood there is a conflict between the animation and physics system. Animation is pushing character forward and collider trying to stop it. But sometimes animation wins and character falls through the wall. Please help me solve this problem.
Thanks.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: PlaymakerAnimatorProxy -> ApplyRootMotion
« Reply #10 on: April 17, 2013, 02:06:17 AM »
Hi,

 can you do a small video showing this? you may have to tweak your physics settings to prevent missed collisions, depending on the speed of your rigid bodies.

bye,

 Jean

9TOFRIDAY

  • Playmaker Newbie
  • *
  • Posts: 39
Re: PlaymakerAnimatorProxy -> ApplyRootMotion
« Reply #11 on: July 07, 2015, 06:41:46 AM »
Code: [Select]
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;

[RequireComponent(typeof(Animator))]
[RequireComponent(typeof(PlayMakerFSM))]
public class PlayMakerAnimatorProxy : MonoBehaviour {

public event Action OnAnimatorMoveEvent;

public event Action<int> OnAnimatorIKEvent;

private Animator anim = null;

void Start()
{
anim = gameObject.GetComponent<Animator>();
}

void OnAnimatorMove()
{
if( OnAnimatorMoveEvent != null )
{
OnAnimatorMoveEvent();
transform.position = anim.rootPosition;
transform.rotation = anim.rootRotation;
}
}

void OnAnimatorIK(int layerIndex)
{
if( OnAnimatorIKEvent != null )
{
OnAnimatorIKEvent(layerIndex);
}
}
}

works perfectly thanks so much!!!!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: PlaymakerAnimatorProxy -> ApplyRootMotion
« Reply #12 on: July 07, 2015, 07:13:24 AM »
Hi,

 ok, so If I get this properly, I should mabe add an option on that proxy to apply rootPosition and rotation? because I guess this is not always required.

Bye,

 Jean

IIKII

  • Full Member
  • ***
  • Posts: 137
  • Lonely developer
    • Patreon
Re: PlaymakerAnimatorProxy -> ApplyRootMotion
« Reply #13 on: December 30, 2018, 10:29:59 AM »
Hi, I started using root motion and I am stuck at moving the parent of the animator object with root motion.

It seems that I need to add 'Animator move' to the animator object right? but this switches "Apply Root Motion to handled by script". Not sure if this is the cause of the problem again??

Well I am really confuse on how to make this work. Any steps?
Support me on Patreon for free adventure games and development insights - https://www.patreon.com/koexstudio