Skip to content

Instantly share code, notes, and snippets.

@webmonch
Created March 8, 2015 18:42
Show Gist options
  • Save webmonch/80112b5637d3f5332cc4 to your computer and use it in GitHub Desktop.
Save webmonch/80112b5637d3f5332cc4 to your computer and use it in GitHub Desktop.
WanderAction
public override ActionResult Execute(RAIN.Core.AI ai)
{
if (!WanderTargetVariable.IsVariable)
throw new Exception("The Choose Wander Position node requires a valid Wander Target Variable");
float tWanderDistance = 0f;
if (WanderDistance.IsValid)
tWanderDistance = WanderDistance.Evaluate<float>(ai.DeltaTime, ai.WorkingMemory);
if (tWanderDistance <= 0f)
tWanderDistance = _defaultWanderDistance;
Vector3 tDirection = new Vector3(UnityEngine.Random.Range(-1f, 1f), 0f, UnityEngine.Random.Range(-1f, 1f));
tDirection *= tWanderDistance;
Vector3 tDestination = ai.Kinematic.Position + tDirection;
if (StayOnGraph.IsValid && (StayOnGraph.Evaluate<bool>(ai.DeltaTime, ai.WorkingMemory)))
{
if (NavigationManager.Instance.GraphForPoint(tDestination, ai.Motor.DefaultStepUpHeight, NavigationManager.GraphType.Navmesh, ((BasicNavigator)ai.Navigator).GraphTags).Count == 0)
return ActionResult.FAILURE;
}
ai.WorkingMemory.SetItem<Vector3>(WanderTargetVariable.VariableName, tDestination);
return ActionResult.SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment