News Forums RAIN General Discussion and Troubleshooting WaypointNetwork - Get Move Target Variable

This topic contains 3 replies, has 2 voices, and was last updated by  redhawk 1 year, 6 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #6464

    redhawk
    Participant

    I’m trying to utilize C# to get the Move Target Variable. Please help. I’m using Rain 2.0.8 (newest version) and Unity 4.3.2 (newest free version).

    Set up - BehaviorTree has PAR - root, WAY - Waypoint Network “WaspNetwork”, Path Target = moveTarget, Move Target Variable = nextTarget. That’s it, I’m not using a Move under WAY. External scripting runs movement

    My script is attached to the Parent and sets the moveTarget just fine (I drag in a GameObject - just for testing).

    Below is my C# script that I’m using for GetItem<Vector3>(“nextTarget”) which should change based on where the parent is going, but it stays set at 0,0,0

    using UnityEngine;
    using System.Collections;
    using RAIN.Core;
    //Basis of this Script is from your Attack&Wander videos for Health.cs
    public class movement : MonoBehaviour {
    	public GameObject moveTarget=null;//My GameObject Target
    	private AIRig aiRig = null;//RAIN AIRig
    	public Vector3 nextTargetLocation;//Vector3 Target I want to track
    	private SteerForTether st; //IGNORE This as this is a UnitySteer Script
    	void Start () 
    	{
    		aiRig=gameObject.GetComponentInChildren<AIRig>();//AIRig setup
    		//IGNORE the below as this is a UnitySteer script
    		st=gameObject.GetComponent<SteerForTether>(); 
    	}
    	void Update () 
    	{
    		//Set moveTarget in working memory - works fine
    		aiRig.AI.WorkingMemory.SetItem("moveTarget",moveTarget);
    		//Get nextTarget location from WaypointNetwork
    		nextTargetLocation=aiRig.AI.WorkingMemory.GetItem<Vector3>("nextTarget");
    		//IGNORE this as it relates to UnitySteer Tether Position Vector3
    		st.TetherPosition=nextTargetLocation;
    	}
    }
    #6467

    prime
    Keymaster

    The nextTarget is probably not a Vector3 - it is probably a MoveLookTarget. Doing a GetItem of the wrong type in most cases will return the default value of the type. For Vector3, that would be 0,0,0

    #6468

    redhawk
    Participant

    Could you provide a suggestion of what I should replace it with. I don’t know what MoveLookTarget translates to in Unity terms. While I can write some C# code and such, I’m really not sure how to convert a MoveLookTarget to something that I can work with to get to the Vector3. Will it convert to a GameObject, and then I get the Vector3? I was hoping that someone could help me by telling me what I’m doing wrong.

    #6469

    redhawk
    Participant

    Nevermind - I got it to work. Ugh, my head hurts.

    So, I left my BT alone. I changed the Rain AIRig to close enough = 2. I created the following code and I also added UnitySteerForTarget (The Target is set to the same target as my moveTarget Object). I like how this looks as the Wasp kind of flies around close to the WaypointNetwork, but not right on top of the network and the turns are more natural looking.

    using UnityEngine;
    using System.Collections;
    using RAIN.Core;
    //Basis of this Script is from your Attack&Wander videos for Health.cs
    public class movement : MonoBehaviour {
    	public GameObject moveTarget=null;//My GameObject Target
    	private AIRig aiRig = null;//RAIN AIRig
    	public Vector3 nextTargetLocation;//Vector3 Target I want to track
    	public RAIN.Motion.MoveLookTarget mt;
    	private SteerForTether st; //IGNORE This as this is a UnitySteer Script
    	void Start () 
    	{
    		aiRig=gameObject.GetComponentInChildren<AIRig>();//AIRig setup
    		mt=aiRig.AI.WorkingMemory.GetItem<RAIN.Motion.MoveLookTarget>("nextTarget");
    		//IGNORE the below as this is a UnitySteer script
    		st=gameObject.GetComponent<SteerForTether>(); 
    	}
    	void Update () 
    	{
    		//Set moveTarget in working memory - works fine
    		aiRig.AI.WorkingMemory.SetItem("moveTarget",moveTarget);
    		mt=aiRig.AI.WorkingMemory.GetItem<RAIN.Motion.MoveLookTarget>("nextTarget");
    		nextTargetLocation=(Vector3)mt.Position;
    		//Get nextTarget location from WaypointNetwork
    		//nextTargetLocation=aiRig.AI.WorkingMemory.GetItem<Vector3>("nextTarget");
    		//IGNORE this as it relates to UnitySteer Tether Position Vector3
    		st.TetherPosition=nextTargetLocation;
    	}
    }
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.