News Forums RAIN Sample Projects, How To, and Code How to Swap AI between two characters

Tagged: 

This topic contains 3 replies, has 2 voices, and was last updated by  prime 2 months, 3 weeks ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #37630

    laurentopia
    Participant

    Hello,
    I just dived into RAIN and love how the system is constructed.
    I am trying to swap AI between two characters, let’s say a cat mind goes into a soldier and vice versa.
    I’m missing a few things, any help is much appreciated:

    First I swap the body:

    GameObject body1;
    body1 = AI1.AI.Body;
    AI1.AI.Body = AI2.AI.Body;
    AI2.AI.Body = body1;

    I want to keep the senses, seems those have to be copied over one by one, is there a simpler way to do this?

    I keep the entities intact since a cat is a cat but what I’d like to do is trigger through a behavior that something is not right about that cat’s behavior - how would I do that elegantly?

    Finally I swap AI gameobject parents

    Transform parent1;
    parent1 = AI1.transform.parent;
    AI1.transform.parent = AI2.transform.parent;
    AI2.transform.parent = parent1;
    • This topic was modified 2 months, 3 weeks ago by  laurentopia.
    #37636

    prime
    Keymaster

    Is there a particular reason to swap the AI? What I mean is, it may be easier to pre-rig the AI, sensors, entities, etc. on both the soldier and the cat, then simply swap only AI memory and possibly the behavior tree.

    In any case - if you actually do need to copy things over, you will need to make changes to:

    - The AI Body. Swap out the AI Body as you suggested.
    - The Sensor Mount Points. If these are placed in particular areas (like the head) then you will have to find proper joints for each. If they are just using the body as a default mount point, then just swap them as you did the AI Body.
    - The Entity Form. This works like the AI Body - by default the Form is set to the Entity’s parent. You will need to swap it out.
    - The Aspect Mount Point. Again, similar to the sensors.

    After you swap everything out, you should call BodyInit on the AI and EntityInit on the entities.

    Swapping out all the various mount points and calling Init can be a bit of a pain, which is why I suggest pre-rigging the AI on each and just swapping out the “mind” parts.

    #37643

    laurentopia
    Participant

    WOW so simple, how I couldn’t think this way is beyond me.
    Would I need to call any method to reinitialize things when I swap memory and brain?

    I didn’t have time to implement what I wanted for that jam and just I just repurposed your commander demo scene into something more sneaky where you only have this conversion gun - converts enemies into (suicidal) friends.
    http://ludumdare.com/compo/ludum-dare-32/?action=preview&uid=37031

    #37650

    prime
    Keymaster

    No - you shouldn’t need to call anything special after you swap out BT and memory.

    re: ludumdare - nice!

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

You must be logged in to reply to this topic.