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, 8 months ago.
-
AuthorPosts
-
December 20, 2022 at 11:51 pm #6029
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); } } } }
December 22, 2022 at 11:31 pm #6041In your script, the AI would likely only move if you are holding down the mouse button, right?
December 23, 2022 at 4:00 am #6042The 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.
December 23, 2022 at 3:42 pm #6049Hmm. 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.
December 23, 2022 at 7:26 pm #6058Could you include a snippet, for the case where you could specify points for the AI to move from unity monobehaviour?
December 23, 2022 at 8:15 pm #6059airig.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.
December 24, 2022 at 3:59 am #6060How 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
December 24, 2022 at 1:58 pm #6065you would just set your moveTarget in your move node to targetLocation
December 24, 2022 at 10:51 pm #6070That’s what I would assume, but the object is still not moving…
December 29, 2022 at 3:55 pm #6076Prime, is this broken in the current versino of Rain?
January 16, 2023 at 6:25 am #6472up
January 16, 2023 at 5:39 pm #6475hmm. pretty sure I looked at this, but I don’t remember. Your filedropper link isn’t working so I can’t re-check.
January 20, 2023 at 5:55 pm #6523After 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??
January 21, 2023 at 10:11 pm #6553The 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).
January 22, 2023 at 12:32 am #6558I’m still not certain how to update the moveTarget variable in the Behavior Tree Move node.
-
AuthorPosts
You must be logged in to reply to this topic.