Esempio n. 1
0
    public void RunFromPoint(Vector3 point, float runDistance)
    {
        StopCoroutine("IdleMotionlessTimer");

        //Play Monkey Sounds (scream)
        PlaySound(screams);

        state = PrimateState.RunningFromSomething;
        UpdateAnim();

        Vector3 directionOfPoint     = point - transform.position; //Get direction from monkey to point
        Vector3 oppositeDirection    = -directionOfPoint * runDistance;
        Vector3 directionFromPrimate = oppositeDirection + transform.position;

        NavMeshHit hit;

        //Check if there is a close point on the navmesh
        if (NavMesh.SamplePosition(directionFromPrimate, out hit, 5, ~NavMesh.GetAreaFromName("Enclosure")))
        {
            agent.destination = hit.position; //Set agent's destination
        }
        else                                  //Try a closer point
        {
            RunFromPoint(point, runDistance * 0.5f);
        }
    }
Esempio n. 2
0
    protected virtual void Update()
    {
        //If we aren't sitting still and have reached the target...
        if (state != PrimateState.IdleMotionless && agent.remainingDistance < agent.stoppingDistance)
        {
            if (state == PrimateState.GoingTowardsSomething)    //Start eating
            {
                state = PrimateState.Eating;

                //Monkey eating sounds
                if (eatingSound != null)
                {
                    eatingSound.Play();
                }

                //Make primate eat
                anim.SetTrigger("Eating");
            }
            else if (state == PrimateState.RunningFromSomething || state == PrimateState.IdleWalking || state == PrimateState.Whistled)    //Go to motionless
            {
                BecomeIdle();
            }
        }

        if (state == PrimateState.GoingTowardsSomething && Time.time > timeToStopGoingTowardsSomething)
        {
            BecomeIdle();
        }


        UpdateAnim();
    }
Esempio n. 3
0
    public void GoTowardsPoint(Vector3 point)
    {
        //Don't go to a food source if we are running from a brick or are currently eating
        if (state != PrimateState.RunningFromSomething || state != PrimateState.Eating)
        {
            StopCoroutine("IdleMotionlessTimer");

            //If we are currently going to another source of food, and our current destination is closer, then do not go to the new point
            if (state == PrimateState.GoingTowardsSomething && agent.remainingDistance < Vector3.Distance(point, transform.position))
            {
                return;
            }

            timeToStopGoingTowardsSomething = Time.time + durationOfFoodAttraction;

            //Play Monkey sounds (see food)
            PlaySound(seeFoods);


            state = PrimateState.GoingTowardsSomething;
            UpdateAnim();

            Vector3 directionOfPoint     = point - transform.position; //Get direction from monkey to point
            Vector3 directionFromPrimate = directionOfPoint + transform.position;

            NavMeshHit hit;
            if (NavMesh.SamplePosition(directionFromPrimate, out hit, 5, ~NavMesh.GetAreaFromName("Enclosure"))) //Get the closest point on the NavMesh
            {
                agent.destination = hit.position;                                                                //Set the navMeshAgent's destination
            }
        }
    }
Esempio n. 4
0
    public void BecomeIdle()
    {
        agent.destination = transform.position;

        state = PrimateState.IdleMotionless;

        //Timer till go to random point (Idle for a psuedo random amount of time)
        StartCoroutine(IdleMotionlessTimer(Random.Range(minIdleTime, maxIdleTime)));
    }
Esempio n. 5
0
    // Start is called before the first frame update
    protected virtual void Start()
    {
        anim = GetComponentInChildren <Animator>();

        agent = GetComponent <NavMeshAgent>();

        state             = PrimateState.IdleWalking;
        agent.destination = transform.position;

        if (SeeFoodObject != null)
        {
            seeFoods = SeeFoodObject.GetComponents <SoundPlayer>();
        }
        if (ScreamObject != null)
        {
            screams = ScreamObject.GetComponents <SoundPlayer>();
        }
    }
Esempio n. 6
0
    public void GoToWhistle(Vector3 direction)
    {
        //Direction should be a unit direction towards where the camera is

        StopCoroutine("IdleMotionlessTimer");

        timeToStopGoingTowardsSomething = Time.time + durationOfFoodAttraction;

        //Play Monkey Sounds (whistle)
        PlaySound(seeFoods);

        state = PrimateState.Whistled;
        UpdateAnim();

        NavMeshHit hit;

        if (NavMesh.SamplePosition(transform.position + direction.normalized * 20, out hit, 50, ~NavMesh.GetAreaFromName("Enclosure"))) //Get the closest point on the NavMesh
        {
            agent.destination = hit.position;
        }
    }
Esempio n. 7
0
    public void GoToRandomPoint()
    {
        //Only go to a random point if we aren't doing anything
        if (state == PrimateState.IdleMotionless)
        {
            Vector3 randomDirection = Random.insideUnitSphere * idleWalkDistance; //Get a random direction
            randomDirection += transform.position;                                //Add it to our position

            NavMeshHit hit;
            //Check if there is a close point on the navmesh
            if (NavMesh.SamplePosition(randomDirection, out hit, 5, ~NavMesh.GetAreaFromName("Enclosure")))
            {
                state = PrimateState.IdleWalking;

                agent.destination = hit.position;   //Set agent's destination
            }
            else
            {
                GoToRandomPoint();
            }
        }
    }