Created
March 8, 2015 18:42
-
-
Save webmonch/80112b5637d3f5332cc4 to your computer and use it in GitHub Desktop.
WanderAction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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