/// <summary>
    /// Apply an agent command to the character
    /// </summary>
    /// <returns>An observation after the action has been applied</returns>
    public Observation ProcessCommand(Command c, int gameTick, NavMeshContainer nav)
    {
        if (gameTick % 199 == 0)
        {
            _Character.SwitchCircleDirection();
        }

        switch (c.cmd)
        {
        case AgentCommandType.DONOTHING:
            break;

        case AgentCommandType.MOVETOWARD:
            AgentCommand <Tuple <Vector3, bool> > move = c as AgentCommand <Tuple <Vector3, bool> >;
            MoveToward(move.arg.object1, move.arg.object2);
            break;

        case AgentCommandType.INTERACT:
            AgentCommand interact     = c as AgentCommand;
            string       interactWith = interact.targetId;
            GameObject.Find(interactWith).GetComponent <Sensor>().Trigger();
            break;
        }

        observation.Observe(_Character, gameTick, nav, c.cmd);
        return(observation);
    }
Beispiel #2
0
    /// <summary>
    /// Returns the indices of vertices that are visible from a character's eye height.
    /// </summary>
    /// <param name="character">The character as a reference point</param>
    public int[] GetAllVisibleVertexIndices(Character character, NavMeshContainer nav)
    {
        Vector3 eyePosition = agentPosition + character.relativeEyePosition;
        var     colliders   = GetNearbyBoundsColliders(eyePosition, character.viewDistanceSqr);

        List <int> visibleVertexIndices = new List <int>();

        for (int i = 0; i < nav.vertices.Length; i++)
        {
            Vector3 v = nav.vertices[i];
            v.y += Constants.epsilon;
            Vector3 diff = v - eyePosition;

            if (diff.sqrMagnitude >= character.viewDistanceSqr)
            {
                continue;                                                     // If the vertex is outside the character's vision radius
            }
            if (colliders.Any(c => c.Contains(v)))
            {
                continue;                                                     // If the vertex is covered by any collider
            }
            if (Physics.Raycast(eyePosition, diff, diff.magnitude))
            {
                continue;                                                     // If the vertex is behind another object
            }
            visibleVertexIndices.Add(i);
        }

        return(visibleVertexIndices.ToArray());
    }
Beispiel #3
0
    /// <summary>
    /// Records the current state of the world from the perspective of a Character
    /// </summary>
    public void Observe(Character character, int gameTick, NavMeshContainer nav, AgentCommandType usedAction)
    {
        agentPosition = character.transform.position;
        tick          = gameTick;
        didNothing    = usedAction == AgentCommandType.DONOTHING;

        entities.Clear();
        AddAllVisibleObjects(character);

        navMeshIndices = GetAllVisibleVertexIndices(character, nav);
    }
Beispiel #4
0
    public static Observation FromCharacter(string agentID, Character character, int gameTick, NavMeshContainer nav, AgentCommandType usedAction)
    {
        Observation obs = new Observation(agentID);

        obs.Observe(character, gameTick, nav, usedAction);
        return(obs);
    }