News Forums General Discussion Custom actions - how to use them?

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

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #5430

    Chris
    Participant

    I’ve saved up some questions I have on custom actions:

    How do I start a coroutine in a custom action? The “StartCoroutine” function does not exist in RAINAction.

    What can I access from ai? Is there anywhere I can see a proper list of what’s in that object? MonoDevelop has a little autocompletion, but RT’s API page seems too undeveloped to be usable (please correct me if I’m wrong).

    How do I go about rotating the AI body? Setting ai.Body.transform.rotation did nothing. Do I have to use the Motor?

    Lastly, if you have any tips to understand custom actions then please share.

    Thanks.

    #5431

    Aaron Mueller
    Participant

    @Chris,

    Regarding starting a coroutine, I too would be curious to know.

    Regarding what you can access from ai? Not sure if this is what you are after, but in the API docs, expand RAIN Namespace -> RAIN.Core Namespace -> AI Class and you should see what you are after (Fields, Properties and Methods). As far as what you can access, in a custom action, you could write something like:

    ai.Body.GetComponent<MyScript>();

    This would allow you to find a C# script attached to the game object that is set to the Body in the AIrig.

    As far as custom actions, what exactly do you seek to understand on Custom Actions?

    I am using several to do specific things that can’t necessarily be done by the Primitive nodes that are already provided. Also, it may be better to write your own to combine things.

    For example, in one earlier version of one of my behavior trees, I had a Random node that had two or 3 Animate nodes. So, it would randomly choose one of three idle animations to play. Later, I decided that I’d like to be able to randomly choose idle or walk animations so I wrote a combination of a custom C# script that attached to my NPC that stores references to all the idle and walk animations respectively. Then my Custom Action randomly picks one walk animation to play when moving to a desired destination. When it gets close it should transition to play a randomly selected idle animation. Unfortunately, it doesn’t quite work exactly as I want it to yet but I haven’t been able to get back to figure out why.

    Hope this helps some. Cheers.

    #5460

    prime
    Keymaster

    Can you give me an example of why you would need a coroutine in a behavior tree action? Usually the purpose of a coroutine is to spread some computing across multiple frames (multiple update calls). Behavior trees already do that, so using a coroutine would be redundant.

    #5488

    Chris
    Participant

    @Aaron Thanks, looking at the API you suggested did give me a better idea of what’s hiding in the AI. But I still feel pretty lost, though I’m sure the wiki will fill in the blanks in time.

    @prime Of course. The AI has a gun that shoots a laser. I’d like to create that laser beam (using a line renderer) and, with a coroutine, hide the beam a second later. Would I be right to say that this should all be done in another script? I.e. a script I find on ai.Body.

    Then how about rotation of the body - is this done with a Motor? A yes/no answer is good enough (in the use case I have right now it’s good enough to use a move node that only turns).

    #5557

    prime
    Keymaster

    @Chris -
    I think the two best options for your example would be
    1) Create the line renderer and make it active in your Start. Use the Execute to watch time and determine when to turn it off. Return RUNNING as long as it should stay active. Turn it off and return SUCCESS when the timer expires.
    2) Do the coroutine thing in a custom script attached to your AI. Use your custom action to trigger it on.
    <br/>
    As I mentioned, coroutines are redundant with behavior tree nodes. They already give you the same capability - to spread your execution out over multiple frames.

    #5558

    prime
    Keymaster

    Do you want to rotate the body toward some point? This can be done with a Move node in the behavior tree. Just set a Face target instead of a Move Target.

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

You must be logged in to reply to this topic.