News › Forums › RAIN › General Discussion and Troubleshooting › Check mecanim parameter
This topic contains 1 reply, has 2 voices, and was last updated by prime 1 month, 2 weeks ago.
-
AuthorPosts
-
January 8, 2023 at 6:13 pm #35027
So I am setting some mecanimator paramters in script to control the state machine of my actor, for example “Prone” = true cause the player to go to the prone state.
Now I dont want to have to duplicate these parameters in the AI WorkingMemory to allow the AI to also know the player has gone prone.
Is there some way to evaluate parameters from the mecanim in the behaviour tree?Note that checking the the actual mecanim state is not suitable as “Prone” is made up of multiple states and transitions. eg: Prone, Crawl
January 11, 2023 at 7:53 am #35037There isn’t a built in node to do it. However, you could write a custom action to do it. It would look something like this:
using UnityEngine; using System.Collections; using System.Collections.Generic; using RAIN.Action; using RAIN.Core; using RAIN.Representation; using RAIN.Animation; using RAIN.Motion; [RAINAction("Check Mecanim Parameter Value")] public class CheckMecanimParameter : RAINAction { public Expression ParameterName = new Expression(); public Expression ParameterValue = new Expression(); private Animator _mecanimAnimator; public override void Start(RAIN.Core.AI ai) { base.Start(ai); if (_mecanimAnimator == null) { if (ai.Animator is MecanimAnimator) _mecanimAnimator = ((MecanimAnimator)ai.Animator).UnityAnimator; if ((_mecanimAnimator == null) && (ai.Motor is MecanimMotor)) _mecanimAnimator = ((MecanimMotor)ai.Motor).UnityAnimator; if (_mecanimAnimator == null) _mecanimAnimator = ai.Body.GetComponentInChildren<Animator>(); } } public override ActionResult Execute(RAIN.Core.AI ai) { if (_mecanimAnimator == null) return ActionResult.FAILURE; if (!ParameterName.IsValid || !ParameterValue.IsValid) return ActionResult.FAILURE; string tParameter = ParameterName.Evaluate<string>(ai.DeltaTime, ai.WorkingMemory); bool tValue = ParameterValue.Evaluate<bool>(ai.DeltaTime, ai.WorkingMemory); if (_mecanimAnimator.GetBool(tParameter) == tValue) return ActionResult.SUCCESS; return ActionResult.FAILURE; } }
-
AuthorPosts
You must be logged in to reply to this topic.