News Forums RAIN General Discussion and Troubleshooting hello! is this thing on

This topic contains 12 replies, has 3 voices, and was last updated by  prime 4 weeks, 1 day ago.

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #35127

    tawdry
    Participant

    Well my 5th post now still no replies to any post iv written so there’s that. I just want to know how to unassign the ai from a character during runtime and assign ai to a charactger during runtime

    #35138

    RyanMitchellGames
    Participant

    I am EXTREMELY new to RAIN and attempting to do the same thing. My thought although it maybe wrong is to have a prefab that is just the game object with the pre-frab rig on it (the thing that create ai creates on a game object as a child) then at run-time instantiate it and add it as a child. Then set the body as the parent you parented it to…

    I could be wrong.

    #35139

    RyanMitchellGames
    Participant

    BTW I am not all the way done but it is working.. you have to reattach a few things back to the main body I have found like mount points etc… we shall see if it works…

    #35140

    RyanMitchellGames
    Participant

    Here is a snippet that does it for me….

    GameObject goBase = Instantiate (Resources.Load("Library/AI/AITest") ) as GameObject;
    if (goBase != null) 
    {
    	goBase.transform.parent = newAvatar.transform; 
    	AIRig aiRigComp = goBase.GetComponentInChildren<AIRig>();
    	if(aiRigComp != null)
    	{
    		aiRigComp.AI.Body = newAvatar;
    		IList<RAIN.Perception.Sensors.RAINSensor> sensesCopyFrom = aiRigComp.AI.Senses.Sensors;
    		for(int i=0;i<sensesCopyFrom.Count;++i)
    		{
    						if(sensesCopyFrom[i].MountPoint != null)
    	                {
    			    sensesCopyFrom[i].MountPoint = newAvatar.transform;
    						}
    						else
    						{
    			    Debug.Log("goAIGuide is null in AIMGR");
    						}
    		}
    	}
    	else
    	{
    	   Debug.Log("aiRigComp == null in AIMGR");
            }
    }
    else
    {
    	Debug.Log("goBase == null in AIMGR");
    }
    #35149

    tawdry
    Participant

    Brilliant man thx I will try it out some time.(The code used for rain really hurts my brain though) I decided to try write my own ai for the bits I was going to use rain for so If it sucks I at least can try your approach. I was also thinking along the lines of swapping out the ai rig char with another rig sans the Ai not a clue how I was going to go about it prolly onenable or something along those lines new to coding so who knows where I would have ended up lol.

    #35161

    prime
    Keymaster

    @RyanMitchellGames - The code you posted is for copying an AI from one body to another. Yes, sensor mount points do need to be updated (glad you posted that).

    Here is an alternative if you are simply adding new AI:
    - Create a prefab of the AI. Instantiate the prefab, attach it to the avatar, set the body, then call AIAwake and AIStart on the rig. If your sensor mount points can be made relative to the prefab, then you don’t have to do anything more.

    @tawdry - and to unassign it, simply destroy the AIRig on the avatar.

    #35165

    tawdry
    Participant

    Hi Prime. Thx for chipping in I put the replies from this post into google translate and it assures me you guys are speaking english lol .

    1 Create a prefab of the AI.// I know what a prefab and a AI is but how do i create a prefab of an Ai?Empty game object with the replacement Ai attached?
    2 Instantiate the prefab, attach it to the avatar.// Attach the empty GO ai as a child of the avatar?
    3 set the body not sure what to do with this line.
    4 then call AIAwake and AIStart on the rig.// say what? how do i call these in unity script?
    5 If your sensor mount points can be made relative to the prefab, then you don’t have to do anything more // Ok so something to do with e=mc2 and solving Pi?
    6 and to unassign it, simply destroy the AIRig on the avatar. // Don’t want to destroy the Ai just cause it to lose conciousness for a bit . For example i have a chap who works during the week and parties on the weekend. So his behaviour tree will be vastly different from week to weekend but he will need to return to week behaviour after letting his hair down .

    #35199

    prime
    Keymaster

    1) When you rig up an AI in RAIN, by default it creates an AI child game object and adds the AIRig to that. You can make a prefab out of just that AI child object.
    2) Attach the AI child object you made into a prefab
    3) Grab the AIRig off your new object:

    AIRig tRig = tNewlyInstantiatedObject.GetComponentInChildren<AIRig>();
    tRig.AI.Body = yourAvatarObject;

    4)

    tRig.AIAwake();
    tRig.AIStart();

    5) By default, the mount point of a Sensor is the parent the AI was originally rigged on. So in most cases you WILL need to grab your sensors and reset their mount point to the new AI Body.
    6) If you are simply switching the Behavior Tree, then all the rest of this is overkill. You can swap the behavior tree on the fly with a single call. On the other hand, if you are simply trying to move the AI Memory between two different setups, that is simple too and doesn’t require copying the AI. Before I go into more detail, what exactly are you trying to accomplish? There may be a far easier solution.

    #35222

    tawdry
    Participant

    Hey Prime

    For example i have a chap who works during the week and parties on the weekend. So his behaviour tree will be vastly different from week to weekend but he will need to return to week behaviour after letting his hair down .

    Yea just want to swap the Ai sometimes . Using my example above put in a weektime behavior Ai then swap to a weekend Ai then back again etc.

    Also if I enter a combat situation want to disable the Ai so i can do the combat in C# then re enable brain.
    Basically want rain to run all the everyday functions but do the specialized actions in C#

    #35223

    prime
    Keymaster

    There’s a SetBehavior call on the BasicMind that let’s you swap out just the behavior tree. This works based on a BTAsset, which you can load through Resources.LoadAssetAtPath(). (You may need to move the BTAssets into a Resource folder)

    To disable an AI temporarily, just do

    AIRig tRig = gameObject.GetComponentInChildren<AIRig>();
    tRig.AI.IsActive = false;
    #35250

    tawdry
    Participant

    Hey Prime
    Thx that works for the disable curious why the use of t(t rig) so much? favorite letter or something else?

    #35299

    prime
    Keymaster

    Coding convention that we try to stick to.

    “_” (underscore) in front of private variables. Lower case first letter, then bumpy caps. _closeEnoughDistance
    “t” in front of locally scoped variables. tCloseEnoughDistance
    “a” in front of method parameters. public void Foo(int aCloseEnoughDistance)

    #35300

    prime
    Keymaster

    Nothing sacred about those - different people use different coding conventions. I’m usually the one who gets sloppy and violates it around here.

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

You must be logged in to reply to this topic.