News Forums RAIN General Discussion and Troubleshooting Using Detect Action Programmatically

Tagged: 

This topic contains 1 reply, has 2 voices, and was last updated by  Shimakaze 4 weeks ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #40394

    Kryptic-Decipher
    Participant

    Hi All,

    Firstly, I would like to thank the developers at Rival Theory for working on this awesome, free AI Engine.

    The problem I am experiencing is trying to programmatically detect other objects (which means I’m not using the BT interface). Here is what I have done:
    1) Attach an Aspect to each object I want to detect.
    2) Attached an AIRig component to each intelligent agent and defined each visual sensor appropriately.
    3) Defined some basic behavior in a custom component:

    using UnityEngine;
    using System.Collections;
    using RAIN.Core;
    using RAIN.BehaviorTrees.Actions;
    using RAIN.Representation;
    public class VisualDetection : MonoBehaviour
    {
    	AIRig ai;
    	DetectAction detect;
    	Expression sensorName;
    	Expression aspectName;
    	public Transform target;
    	void Start()
    	{
    		ai = gameObject.GetComponentInChildren<AIRig>();
    		detect = new DetectAction();
    		sensorName = new Expression();
    		aspectName = new Expression();
    	}
    void Update()
    {
    	sensorName.ExpressionAsEntered = "FrontSensor";
    	aspectName.ExpressionAsEntered = "Infected";
    	detect.sensor = sensorName;
    	detect.aspect = aspectName;
    	detect.aspectObjectVariable = "SensedAgent";
    	Debug.Log (ai.AI.WorkingMemory.GetItem ("SensedAgent"));
    	if (ai.AI.WorkingMemory.GetItem("SensedAgent") != null)
    	{
    		Debug.Log ("GameObject Detected");
    	}
    }

    However, it doesn’t seem to work. Any solutions on how I can get it to work?

    Thanks in advance

    #40395

    Shimakaze
    Participant

    Because you do not use BT, the detect action node does not be executed.
    You should call Execute() by youself.
    However, why you want do this?
    Write your own detect algorithm is more easier.

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

You must be logged in to reply to this topic.