News Forums RAIN General Discussion and Troubleshooting Problems getting ref to Player detected

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

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

    forbidden
    Participant

    Hello All,
    I am new to Rain AI, but I got all the basic stuff working..
    Ai walking around, able to detect a player and chase them etc..

    Now, I am having a problem though getting the plays position or transform.
    I want to shoot a projectile at the player, but so far no luck..

    My script is below, my playerposition is always zero.
    any help would be appreciated.

    public override ActionResult Execute(RAIN.Core.AI ai)
        {
    			Debug.Log ("attack");
    			//get enemy position..
    			Vector3 EnemyPosition = new Vector3(ai.Kinematic.Position.x, ai.Kinematic.Position.y,ai.Kinematic.Position.z);
    			Vector3 PlayerPostion = ai.WorkingMemory.GetItem<Vector3>("varPlayer");
    			Debug.Log(PlayerPostion);
            return ActionResult.SUCCESS;
        }
    • This topic was modified 3 months, 2 weeks ago by  forbidden.
    • This topic was modified 3 months, 2 weeks ago by  forbidden.
    #34093

    forbidden
    Participant

    I figured it out…

    RAIN.Entities.Aspects.RAINAspect PlayerA= ai.WorkingMemory.GetItem<RAIN.Entities.Aspects.RAINAspect >("varPlayerAspect");
    		    Debug.Log(PlayerA.Position);

    I had to set the aspect variable..

    #34094

    forbidden
    Participant

    Having problems getting transform rotation.

    #34095

    prime
    Keymaster

    Here’s a helpful trick. Often times you need to get the position of an object in memory, but you don’t know (or care to know) what the type of the object is (e.g., game object, aspect, vector3).

    You can do this:

    //see the API docs or just look at the method signature - there are two additional optional parameters
    MoveLookTarget tTarget = MoveLookTarget.GetMoveLookTargetFromVariable(ai.WorkingMemory, "variableName");
    Vector3 tPosition = tTarget.Position;

    For the other issue - in your detect node there are 3 fields you can assign:
    Aspect Variable - this assigns the actual aspect to your variable. seems like this is what you used
    Mount Point Variable - this assigns the mount point of the aspect to your variable.
    Form Variable - this assigns the game object associated with the Form field of the Entity. I know that sounds complicated, but this is the one you probably want, and will give you the player game object.

    Just as a last bit of explanation. Entities are used to describe objects. The object that is being described by the Entity is called the “Form”. Aspects are the pieces of information associated with an Entity that describe aspects of the Form. Aspects can be associated with specific positions on the Form - these are Mount Points.

    Example: I want to describe the Player as an enemy. I add an Entity to the Player in my scene. The Entity Form field will be set to Player. I then add a Visual Aspect to my Entity. The Visual Aspect is called “enemy” and tells me that when I see the aspect with a Visual Sensor, I can tell that I’m looking at an enemy. I can mount the aspect to the enemy’s head so that when I look at the enemy (or shoot at him) I am shooting up at the head, not at the feet.

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

You must be logged in to reply to this topic.