Advertisement
Guest User

Waypoint Network Code RAIN Unity3D

a guest
Mar 24th, 2014
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using RAIN.Core;
  4. using RAIN.Action;
  5. using RAIN.Navigation;
  6.  
  7. [RAINAction("Choose Wander Location2")]
  8. public class ChooseWanderTarget2 : RAINAction
  9.    
  10.    
  11. {
  12.     // add in a cube and rename Indicator to display target location
  13.     //private GameObject Indicator;
  14.    
  15.     public ChooseWanderTarget2()
  16.     {
  17.         actionName = "ChooseWanderTarget2";
  18.     }
  19.    
  20.     public override void Start(AI ai)
  21.     {
  22.         base.Start(ai);
  23.         // Use this to assign a cube with collider disabled called indicator to use and an idicator for target position
  24.         //Indicator = GameObject.Find ("Indicator");
  25.     }
  26.    
  27.     public override ActionResult Execute(AI ai)
  28.     {
  29.         Vector3 loc = Vector3.zero;
  30.         RAIN.Navigation.Pathfinding.RAINPath myPath = null;
  31.         do {
  32.             loc = new Vector3(ai.Kinematic.Position.x + Random.Range(0f, 8f),
  33.                               ai.Kinematic.Position.y,
  34.                               ai.Kinematic.Position.z + Random.Range(-8f, 8f));
  35.            
  36.         } while ((Vector3.Distance(ai.Kinematic.Position, loc) < 1f) && !ai.Navigator.GetPathTo(loc, 10, out myPath));
  37.        
  38.        
  39.         ai.WorkingMemory.SetItem<Vector3> ("wanderTarget", loc);
  40.         // Use this to move the object (ie a cube to the target location
  41.         //Indicator.transform.position = loc;
  42.        
  43.         return ActionResult.SUCCESS;
  44.     }
  45.    
  46.     public override void Stop(AI ai)
  47.     {
  48.         base.Stop(ai);
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement