News Forums Updating to RAIN Initiating a move order through C# script.

This topic contains 6 replies, has 2 voices, and was last updated by  AlexDyre 1 month, 3 weeks ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #12304

    AlexDyre
    Participant

    I’m currently quite perplexed on this as I haven’t been able to find any information on if this is possible.

    My aim is with a mouse click, I am sending the click position to the AI’s working memory. Is it possible from there to tell the AI to execute a “Move” to move to that given position?

    #12424

    CodersExpo
    Participant

    As you have probably read, using a raycast will return the hit.point in the world-space. If you are not clicking on a collider, then how far away from the camera should your input return a world-space position. It would be like pointing at the sky and saying “put a star there”, where? how far away?

    If you don’t have a collider to raycast against for depth reference, but you know the distance from the camera you would like the point to be, you can use Ray :

    private float _distance = 4.5f;

    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    Vector3 point = ray.origin + (ray.direction * _distance);

    _ai.WorkingMemory.SetItem<Vector3>(“MemoryVariableToMoveTo”, point);

    Just use this memory variable now as the moveTo Target. Hope this helps.

    pss…if you just want to assign this to the ai motor while your here in the code rather than a WorkingMemory variable do this..

    _ai.Motor.moveTarget = new MoveLookTarget(){VectorTarget=point};

    • This reply was modified 1 month, 3 weeks ago by  CodersExpo.
    #12614

    AlexDyre
    Participant

    Hi, and thanks for taking the time to reply!

    As you suggested, I already have a raycast to return my point and I tried you suggestion of using

    _ai.Motor.moveTarget = new MoveLookTarget(){VectorTarget=point};

    To move the unit, however, with this method the unit will move right through solid objects and such, should I be perusing another method to have the unit move on command?

    As I have currently, when I have the unit selected and click a position, the Vector3 is transferred to the AI’s working memory, but I am not sure on how to set the “waypoint” as with the method you suggested, as I explained the unit would move straight through solid objects to get to the specific point (and very slowly).

    #12644

    CodersExpo
    Participant

    If you haven’t gone through the wiki documentation please do. I think you’ll find the answer you are looking for here http://rivaltheory.com/wiki/doku.php?id=environment:waypointcollections:start

    If you have static objects in the game you want to avoid build navigation targets or waypoints around them. Issue instructions to your AI for the waypoint or target you want to move to. You could put Entity/Aspects on objects and detect them, then move to the nearest waypoint too.

    Right now there is no avoidance system in RAIN (I believe that is coming….need to check with Jester), so you may need to use your own method of detecting and avoiding.

    Here is a simple example that might help get you started learning obstacle avoidance: http://www.burgzergarcade.com/tutorials/javascript/obstacle-avoidance-unity-3d

    Does this help?

    • This reply was modified 1 month, 3 weeks ago by  CodersExpo.
    #12672

    AlexDyre
    Participant

    Ah, thank you very much for this.

    #12681

    CodersExpo
    Participant

    Confirmed with Jester “The next release of RAIN will have obstacle avoidance”. Yeah!

    #12684

    AlexDyre
    Participant

    That sounds awesome actually, and once again, thanks for the help and taking the time to do so :)

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

You must be logged in to reply to this topic.