News Forums RAIN General Discussion and Troubleshooting How do I make my character move to a vector3?

This topic contains 8 replies, has 4 voices, and was last updated by  prime 2 years, 7 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #32885

    affy
    Participant

    I just got rain, been reading the documentation over and over, but I still have no idea how I would actually move my character to a given position.

    I created an AI, using the “Create AI” button in the “RAIN” Menu, while having my capsule primitive object selected.
    Then, I have a script attached to the capsule called ‘Unit’, which contains the following:

    
    using UnityEngine;
    using System.Collections;
    using RAIN.Core;
    public class Unit : MonoBehaviour {
    	private AIRig rig;
    	// Use this for initialization
    	void Start () {
    		rig = gameObject.GetComponentInChildren<AIRig>();
    		rig.AIStart ();
    	}
    	public void giveOrder(Vector3 position) {
    		//rig.AI.goHerePlease(position)
    	}
    }
    

    Please help, I’m lost

    • This topic was modified 2 years, 7 months ago by  affy.
    #32887

    Gyfis
    Participant

    I believe you want to use script to do the moving, right?

    Do you just want to translate the rig by/to the position vector3 or do you want to use NavMesh and navigation to calculate the ideal path?

    If you just want to translate, try using ai.Motor:

    
    public void giveOrder(Vector3 position) {
    // optional step - setting the speed:
    rig.AI.Motor.Speed = 1.0f;
    // the actual moving - you call MoveTo on the Motor object on AI, which does all the moving around
    rig.AI.Motor.MoveTo(position);
    }
    

    With NavMeshes and navigation it get’s a bit more complicated, will write more if needed.

    #32888

    affy
    Participant

    Hi Gyfis, yeah I wanna have the AI figure out the path and move along it etc.

    #32890

    Gyfis
    Participant

    OK! For that to work, you need some things done:
    1) NavMesh
    2) Waypoints / Patrol routes or navigation targets
    and maybe some others.
    NavMesh is for your character and navigation to work properly (pretty easy, you just set it up and it uses whatever magic it has to move your character from point A to point
    and Waypoints and navigation targets are ways to tell the AI where to move.

    I strongly recommend you two things:
    1) switch from documentation to tutorials. The documentation, while providing a lot of useful info, doesn’t tell you what to do in order to accomplish what you want.
    2) use visual inspector and graphic stuff instead of scripts and code. I don’t know how skillful coder / programmer you already are, but it was easier to start with the visual stuff before entering the coding, even though I make living with coding.

    With that said, this is IMHO a great way to start with Rain AI, waypoints and moving things around:

    It explains pretty much everything you need with commented steps, and it was a good start for me.

    Hope this helps you!

    Take care affy

    #32896

    prime
    Keymaster

    (1) Generate a nav mesh. RAIN->Create NavMesh. Position and size the box so it covers your scene, then hit generate.
    (2) Create a behavior tree. Give it a single Move node. set the move target to (x, y, z) where x,y,z are your coordinates
    (3) Set the AI to use your behavior tree. Click on the AI object on your character. Click on the head icon on the AIRig to select the Mind tab. Drag the behavior tree from your project view (It will be in the AI/BehaviorTrees folder) into the Behavior Tree Asset field.

    Hit Play.

    #32897

    prime
    Keymaster

    In code the command is

    ai.Motor.MoveTo(Vector3);

    #32905

    affy
    Participant

    This is confusing. Is there no way to make it move without messing with the behavior tree stuff?

    Literally, all I need right now is to tell the AI to move to a target, and I wanna do it from a UnitCommander script, attached to my Main Camera.

    • This reply was modified 2 years, 7 months ago by  affy.
    #33189

    tapticc
    Participant

    Hi, I have a similar query, I am using a behaviour tree and setting a followPosition variable to the current player’s position so an NPC follows me. I am setting the followPosition variable using an AO.WorkingMemory.SetItem<Vector3> and the character is moving towards the player, but it is not using the NavMesh to bypass non-walkable areas.

    I can understand why this is the case - I have told the NPC to move towards the player, but I am unsure on the best way to move the NPC to a moving target (the player) but stick to the NavMesh.

    Any tips please?

    #33194

    prime
    Keymaster

    @tapticc -

    - If you want the character to follow the player, you may not want to use a Vector3 unless you are recalculating the position frequently. Move target can be a gameObject as well.

    - AI will stick to the NavMesh if (1) the Motor has Valid Path Required checked, and (2) there is a useable NavMesh covering both the AI and the move target. That happens automatically as long as you are using one of the built-in Motors.

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.