Beispiel #1
0
    /*BOIDS*/
    void FixedUpdate()
    {
        RaycastHit[] hits = Physics.SphereCastAll(this.transform.position, 4f, Vector3.forward);
        //Debug.DrawLine (this.transform.position,this.transform.position+this.transform.forward, Color.blue);

        steeringForce += GregarianWeights.w_inercia * steeringForce;
        //Debug.DrawLine (this.transform.position,this.transform.position+steeringForce, Color.green);

        steeringForce += GregarianWeights.w_random * randomVector();

        steeringForce += calculateNavigationVector() * GregarianWeights.w_navigation;
        steeringForce += calculateSeparationVector(hits) * GregarianWeights.w_separation;
        steeringForce += calculateCohesionVector(hits) * GregarianWeights.w_cohesion;
        steeringForce += calculateAligmentVector(hits) * GregarianWeights.w_aligment;


        steeringForce      = Vector3.ClampMagnitude(steeringForce, navMeshAgent.speed);
        steeringForce.y    = 0;
        transform.rotation = Quaternion.Lerp(
            transform.rotation,
            Quaternion.LookRotation(steeringForce, Vector3.up),
            navMeshAgent.angularSpeed * Time.deltaTime
            );
        rb.velocity = transform.forward * navMeshAgent.speed;

        if (mem.areEnemiesClose())
        {
            if (mem.getCloseEnemy().tag == "Player")
            {
                shootArrow(mem.getCloseEnemy());
            }
        }

        Debug.DrawLine(this.transform.position, this.transform.position + steeringForce, Color.red);
    }
    void FixedUpdate()
    {
        mem.deleteNullObjects();
        Vector3 destination = agent.destination;         //añadir que el destino no coincide con una fruta!!

        if (Vector3.Angle(destination - this.transform.position, this.transform.forward) > 90f)
        {
            this.gameObject.transform.LookAt(destination);
            return;
        }

        if (mem.areEnemiesClose())
        {
            //Debug.Log("Los enemigos están cerca");
            NavMeshHit hit;
            NavMesh.SamplePosition(2 * this.transform.position - mem.getCloseEnemy().transform.position, out hit, 12f, NavMesh.AllAreas);
            destination = hit.position;
            //Debug.DrawRay(destination, Vector3.up,Color.green,1f);
        }

        else if (fsm.amIHungry() && mem.doIknowWhereFruitIs())
        {
            if ((agent.destination - mem.getFruit()).sqrMagnitude < 0.01f)
            {
                //Debug.Log("Estoy cerca de la comida");
                return;
            }
            else
            {
                //Debug.Log("Tengo hambre mamá");
                destination = mem.getFruit();
            }
        }
        else if (fsm.amIWandering())
        {
            destination = takeAPhysicalNavigableLook();
        }
        else if (!agent.hasPath)
        {
            destination = takeAPhysicalNavigableLook();
        }
        else
        {
            return;
        }


        mem.setNewPointInPath(destination);
        agent.SetDestination(destination);

        //Debug.DrawRay(agent.destination,(Vector3.up*100),Color.white);
    }