News Forums RAIN General Discussion and Troubleshooting How to access a variable for waypoints?

This topic contains 7 replies, has 2 voices, and was last updated by  CodersExpo 2 years, 6 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #11962

    cdillard
    Participant

    Hello all

    I am curious about a couple things I can’t seem to locate a “how to” for. Instead of answering the question, if one would like to just point me in the correct direction, I would be very appreciative.

    Is there a way to directly control which waypoint to go to by waypoint name? Is there some way to say, for example, if i press the D key, the AI directs to the EAST named waypoint and if I press the W key, the AI navigates to the waypoint named NORTH?

    Is there a way to use a waypoint alone as a game object? Are these components of the gameobject Waypoint Routes?

    Thanks for your time. Forgive my ignorance. It won’t last long, I assure you.

    Regards.

    #12162

    cdillard
    Participant

    Well, after plugging around with this, I decided to just use standard objects instead of the waypoint system in RAIN. I would have liked to still use it if anyone knows a way to directly tell a character to go to a specific waypoint though.

    #12191

    CodersExpo
    Participant

    You should be able to do something like this. Just give your waypoints a name.

    public override void Start(AI ai)
    {
    _isAtTarget = ai.WorkingMemory.GetItem<bool>(“Redirected”);
    _moveToWayPoint = ai.WorkingMemory.GetItem<string>(“WayPointName”);

    if(!_isAtTarget)
    {
    var wpset = NavigationManager.Instance.GetWaypointSet(“route”);
    var wps = wpset.Waypoints;

    foreach(var wp in wps)
    {
    if(wp.waypointName == _moveToWayPoint)
    {
    _nextPos = w.position;
    ai.Motor.moveTarget = new RAIN.Motion.MoveLookTarget(){VectorTarget = _nextPos};
    break;
    }
    }

    }

    base.Start(ai);
    }

    public override ActionResult Execute(AI ai)
    {
    if(!ai.Motor.IsAtMoveTarget)
    {
    ai.Motor.Speed = 2;
    ai.Motor.Move();
    return ActionResult.RUNNING;
    }

    _isAtTarget = true;
    ai.WorkingMemory.SetItem<bool>(“Redirected”, _isAtTarget);
    return ActionResult.SUCCESS;
    }

    • This reply was modified 2 years, 6 months ago by  CodersExpo.
    #12203

    cdillard
    Participant

    Thanks, CodersExpo, for your response. I understand how this works, but I don’t understand this:

    foreach(var wp in wps)
    {
    if(wp.waypointName == _moveToWayPoint)
    {
    _nextPos = w.position;
    ai.Motor.moveTarget = new RAIN.Motion.MoveLookTarget(){VectorTarget = _nextPos};
    break;
    }

    What is _nextPos and w?

    #12206

    CodersExpo
    Participant

    Sorry I hope this helps. Small typo on w = wp. This is a waypoint

    foreach(var wp in wps)
    {
    if(wp.waypointName == _moveToWayPoint)
    {
    //For all waypoints in the waypoint collection, if the name is equal to the one we
    //want to move to, get that vector3 position
    _nextPos = wp.position;
    ai.Motor.moveTarget = new RAIN.Motion.MoveLookTarget(){VectorTarget = _nextPos};
    break;
    }

    #12217

    cdillard
    Participant

    No problem with a typo. I appreciate all your help in trying to understand all of this.

    Just to clarify, is this example you have given applicable to both Waypoint Patrols and Waypoint Networks or only one? I am asking because I still can’t get it to work and thought that maybe it was because I have some of the small things set up wrong.

    #12218

    cdillard
    Participant

    Through a series of debug.logs, I have determined that everything is working, but when it gets to
    ai.Motor.moveTarget = new RAIN.Motion.MoveLookTarget(){VectorTarget = _nextPos};
    break;
    it isnt going to that point. the position is being accessed fine.

    EDIT:

    Ok, it is actually going to the point I specify, but only after the waypoint route is completed. I am using a waypoint route, not a network. Is that my problem, you think?

    • This reply was modified 2 years, 6 months ago by  cdillard.
    #12324

    CodersExpo
    Participant

    Not sure, I would have to mess around with this more to flush out all scenarios. I was using a way route too, so not exactly sure what’s going on. Do you call this at the start of the search or in the middle randomly? There may be more we can do but as I said I would have to toy with it. I’ll see what I can come up with. Right now I’m trying to get a tutorial on the mecanim out so it might be a day or so.

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

You must be logged in to reply to this topic.