News Forums RAIN General Discussion and Troubleshooting Rain - simply moving a character around navmesh

This topic contains 17 replies, has 2 voices, and was last updated by  prime 2 years, 1 month ago.

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #6029

    inac
    Participant

    I’m trying to get started with Rain scripting to just move a character around a navmesh - I can’t seem to propagate a moveTarget vector3 to the rain AI (ie, character isn’t moving). My AI contains a move and animation in parallel…

    using UnityEngine;
    using System.Collections;
    using RAIN.Core;
    public class MoveHippo : MonoBehaviour {
    	public Vector3 moveTarget;
    	AIRig airig=null;
    	// Use this for initialization
    	void Start () {
    		airig = gameObject.GetComponentInChildren <AIRig>();
    	}
    	// Update is called once per frame
    	void Update () {
    		if(airig.AI.Motor.IsAtMoveTarget)animation.Stop();
    		#if UNITY_EDITOR
    		if(!Input.GetMouseButtonDown(0))return;
    #else
    		if(Input.touchCount<1)return;
    #endif
    		Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    		RaycastHit hit;
    		if(Physics.Raycast(ray, out hit,3000f)){
    			if(hit.transform.gameObject.tag == "Terrain"){
    				moveTarget = hit.point;
    				airig.AI.Motor.MoveTo (moveTarget);
    			}
    		}
    	}
    }
    
    #6041

    prime
    Keymaster

    In your script, the AI would likely only move if you are holding down the mouse button, right?

    #6042

    inac
    Participant

    The AI does not move at all even when I hold down the mouse…

    Can you check if I am referencing your API right for assigning moveTarget / MoveTo? My previous issue was due to changes in the latest version vs. the tutorial/docs.

    #6049

    prime
    Keymaster

    Hmm. The problem is that you are doing this in a separate monobehaviour, which means the timing isn’t working out in relation to the AI timing. What you are trying to do isn’t impossible, but it is certainly not the way RAIN is intended to be used, so you are going against the workflow.

    The AI Update loop does Pre, Sense, Think, and Act in sequence, all in the same Update. Because of that, the results of your MoveTo call are never applied (the Motor applies Motion transforms in Act.) The ways you can insert your code into the process are:
    1) Turn off the setting for “Use Unity Messages” and then call those methods yourself manually.
    2) Move your code so that it happens in AI Think or Act.
    3) Use a Behavior Tree and a custom action.

    You could also try calling airig.AI.Motor.UpdateMotionTransforms yourself after your MoveTo.

    Overall, I recommend trying to fit back into the normal workflow. Use your code to set the move target for the AI, but use an AI Behavior tree to actually move to the move target.

    #6058

    inac
    Participant

    Could you include a snippet, for the case where you could specify points for the AI to move from unity monobehaviour?

    #6059

    prime
    Keymaster
    airig.AI.WorkingMemory.SetItem<Vector3>("targetLocation", loc);

    That will set a vector target called targetLocation into working memory. That variable will be accessible from the Behavior Tree.

    #6060

    inac
    Participant

    How do I access this from the behaviour tree?

    I’ve tried matching moveTarget variable in the move segment to airig.AI.WorkingMemory.SetItem<Vector3>(“moveTarget”, loc); … the value is still not being passed

    #6065

    prime
    Keymaster

    you would just set your moveTarget in your move node to targetLocation

    #6070

    inac
    Participant

    That’s what I would assume, but the object is still not moving…

    http://www.filedropper.com/testmovecue

    #6076

    inac
    Participant

    Prime, is this broken in the current versino of Rain?

    #6472

    inac
    Participant

    up

    #6475

    prime
    Keymaster

    hmm. pretty sure I looked at this, but I don’t remember. Your filedropper link isn’t working so I can’t re-check.

    #6523

    inac
    Participant

    After setting

    airig.AI.WorkingMemory.SetItem<Vector3>("moveTarget", new Vector3(1,0,3));

    I then call

    print(airig.AI.Motor.moveTarget.Position.ToString());

    the return is actually Vector3.zero…

    I am not sure if the right var is being set??

    • This reply was modified 2 years, 2 months ago by  inac.
    • This reply was modified 2 years, 2 months ago by  inac.
    • This reply was modified 2 years, 2 months ago by  inac.
    • This reply was modified 2 years, 2 months ago by  inac.
    #6553

    prime
    Keymaster

    The first call sets the moveTarget variable in memory. However, that does not have any impact on the Motor directly. RAIN doesn’t have any built in variables that impact behavior like that.

    If you are using a Behavior Tree Move node, and if the move node uses the moveTarget variable as its move target, then whenever that node runs it will set the Motor move target to the current value of the variable (and will attempt to move to that position).

    #6558

    inac
    Participant

    I’m still not certain how to update the moveTarget variable in the Behavior Tree Move node.

Viewing 15 posts - 1 through 15 (of 18 total)

You must be logged in to reply to this topic.