Пример #1
0
    public override Status update(EntityKnowledgeFacade entity, UInt32 request, FaceEntityParam parameters, StaticObject paramsOut, float dt)
    {
        if (parameters.targetEntity != "none")
        {
            for (uint i = 0; i < nbrEntity; i++)
            {
                if (i != entity.entity.entityID)
                {
                    Aname = entity.getEntityKnowledge(i).getString("name");
                    if (Aname == parameters.targetEntity)
                    {
                        entity.getEntityKnowledge(i).retrieve(entity.getEntityKnowledge(i).getProperty("position"), out position);
                    }
                }
            }
        }

        if (parameters.targetID != -1)
        {
            index = (uint)parameters.targetID;
            entity.getEntityKnowledge(index).retrieve(entity.getEntityKnowledge(index).getProperty("position"), out position);
        }

        if (parameters.pos != Vector3.zero)
        {
            position = parameters.pos;
        }

        // get the transform of the entity asked to face
        Transform self = entity.entity.transform;
        // create a quaternion to look along the direction of the targetPosition
        Quaternion lookAt = Quaternion.LookRotation((position - self.position).normalized);

        // slowly rotate toward it
        self.rotation = Quaternion.RotateTowards(self.rotation, lookAt, 180f * dt);

        // if almost facing ...
        if (RotationEquals(self.rotation, lookAt))
        {
            // then it is time to end the facing
            return(Status.succeeded);
        }
        // else we will continue rotating
        return(Status.running);
    }
Пример #2
0
    public override Status update(EntityKnowledgeFacade entity, UInt32 request, GotoEntityParam parameters, StaticObject paramsOut, float dt)
    {
        if (parameters.target != "none")
        {
            for (uint i = 0; i < nbrEntity; i++)
            {
                if (i != entity.entity.entityID)
                {
                    Aname = entity.getEntityKnowledge(i).getString("name");
                    if (Aname == parameters.target)
                    {
                        entity.getEntityKnowledge(i).retrieve(entity.getEntityKnowledge(i).getProperty("position"), out position);
                        if (parameters.location == true)
                        {
                            entity.getKnowledge().setString("location", "none");
                            entity.getKnowledge().setString("interactName", "none");
                            entity.getKnowledge().setString("destination", Aname);
                        }
                    }
                }
            }
        }

        if (parameters.targetID != -1)
        {
            index = (uint)parameters.targetID;
            entity.getEntityKnowledge(index).retrieve(entity.getEntityKnowledge(index).getProperty("position"), out position);
            if (parameters.location == true)
            {
                entity.getKnowledge().setString("location", "none");
                entity.getKnowledge().setString("interactName", "none");
                //entity.getKnowledge().setString("destination", Aname);
            }
        }


        //index = (uint)parameters.target;
        //Debug.Log(index);
        //entity.getEntityKnowledge(index).retrieve(entity.getEntityKnowledge(index).getProperty("position"), out position);

        GameObject   self = entity.entity.gameObject;
        NavMeshAgent nav  = entity.entity.GetComponent <NavMeshAgent>();

        // Create a vector from the enemy to the last sighting of the player.
        Vector3 sightingDeltaPos = position - self.transform.position;

        // If the the last personal sighting of the player is not close...
        if (sightingDeltaPos.sqrMagnitude > 4f)
        {
            // ... set the destination for the NavMeshAgent to the last personal sighting of the player.
            nav.destination = position;
        }
        if (sightingDeltaPos.sqrMagnitude < parameters.threshold)
        {
            nav.Stop();
            if (parameters.location == true)
            {
                entity.getKnowledge().setString("location", Aname);
                entity.getKnowledge().setString("interactName", Aname);
                entity.getKnowledge().setString("destination", "none");
            }
            return(Status.succeeded);
        }

        /*for(uint i = 0; i < nbrEntity; i++){
         *      if(entity.getEntityKnowledge(i).getBool("interruption") ==  true)
         *      {
         *              nav.Stop();
         *              return Status.succeeded;
         *      }
         * }*/

        return(Status.running);
    }