Beispiel #1
0
    void GoToNextPoint()
    {
        // Returns if no points have been set up
        if (PatrolPoints.Length == 0)
        {
            return;
        }

        // Function from NavMeshController script, we are feeding it the PatrolPoints' Vector3 position
        controller.NavMeshProvider(PatrolPoints[currentPatrolPoint].position);

        // Choose the next point in the array as the destination, cycling to the start if necessary.
        currentPatrolPoint = (currentPatrolPoint + 1) % PatrolPoints.Length;
    }
Beispiel #2
0
    public void StartChasing()
    {
        float distance = Vector3.Distance(transform.position, player.transform.position);

        if (distance < DistanceDetect)
        {
            controller.NavMeshProvider(player.transform.position);
            agent.stoppingDistance = 2f;
        }
    }
Beispiel #3
0
    public void StartRepeling()
    {
        float distance = Vector3.Distance(transform.position, player.transform.position);

        if (distance < DistanceDetect)
        {
            Vector3 dirToPlayer = transform.position - player.transform.position;
            Vector3 newPos      = transform.position + dirToPlayer;
            controller.NavMeshProvider(newPos);
        }
    }
    // When the baehavior and targetting script is called, the script should be fed the desired tergetting radius and the gameobject that should be targeted within that radius
    void BehaviorSetup(GameObject User, float Radius, GameObject Target, script Action)
    {
        DesiredAction = Action;
        User.AddComponent <SphereCollider>() as SphereCollider;
        User.GetComponent <SphereCollider> .radius = Radius;
        //finds the closest object of the target type
        if (objects.Count >= 1)
        {
            Vector3 currentPosition = this.transform.position;
            float   nearestDist     = Mathf.Infinity;

            foreach (GameObject obj in objects)
            {
                Vector3 dist    = obj.transform.position - currentPosition;
                float   distSqr = dist.sqrMagnitude;
                if (distSqr < nearestDist)
                {
                    nearestDist  = distSqr;
                    WhatToTarget = obj;
                }
            }


            inRange = true;
            //here is where i call the navmesh script using obj.transform as the destination
            //hopefully the navmesh script gets called properly, and accepts the .position
            Navigate.NavMeshProvider(WhatToTarget.transform.position);
            //Conditional arguements for different actions, must fit the different call limitations of the action scripts
            if (DesiredAction == Pickupper)
            {
                //issue: calling pickup requires a button to be pressed
                pickupper.ButtonCheck();
            }
            if (DesiredAction == Usable)
            {
                //as per documentation, this should use the targeted object and not destroy it afterwards
                ActionUse.Use(WhatToTarget, false);
            }
        }
    }
Beispiel #5
0
    // Update is called once per frame
    void FixedUpdate()
    {
        Debug.Log("Update firing");
        Debug.Log(objects.Count);
        DesiredAction = Action;
        //finds the closest object of the target type
        if (objects.Count > 0)
        {
            Debug.Log("Polling objects");
            Vector3 currentPosition = this.transform.position;
            float   nearestDist     = Mathf.Infinity;

            foreach (GameObject obj in objects)
            {
                Vector3 dist    = obj.transform.position - currentPosition;
                float   distSqr = dist.sqrMagnitude;
                if (distSqr < nearestDist)
                {
                    nearestDist  = distSqr;
                    WhatToTarget = obj;
                    Debug.Log("Target has fired");
                }
            }

            Debug.Log("loop broken");
            Debug.Log(WhatToTarget.transform.position);

            inRange = true;
            //here is where i call the navmesh script using obj.transform as the destination
            //hopefully the navmesh script gets called properly, and accepts the .position
            NewDirection = (WhatToTarget.transform.position);
            Navigate.NavMeshProvider(NewDirection);
            //Navigate.NavMeshProvider(WhatToTarget.transform.position);
            Debug.Log("Navmesh has fired");

            if (this.action_distance > Vector3.Distance(this.transform.position, NewDirection))
            {
                Debug.Log("arrived");
                ActionPickup.PickUp();
            }

            //There needs to be a check for when the navmesh has finished before calling the desired action script

            /*
             * //otherGameObject.GetComponent("OtherScript").DoSomething();
             * //Conditional arguements for different actions, must fit the different call limitations of the action scripts
             * if(DesiredAction == Pickupper2){
             * //issue: calling pickup requires a button to be pressed, and does not specify what to pick up in the function
             * ActionPickup.PickUp();
             * }
             * if(DesiredAction == Usable){
             * //as per documentation, this should use the targeted object and not destroy it afterwards
             * ActionUse.Use(WhatToTarget, false);
             * }
             *
             * if(DesiredAction == Break){
             * //this should destroy the target object. Presupposes that the object being targetted with the purpose of breaking has the script attached
             * //ideally should simply call the break function on the targeted object
             * //ActionBreak.WhatToTarget.explode();
             * WhatToTarget.GetComponent<"Break">.explode();
             * }
             *
             * if(DesiredAction == Combust){
             * //should burn the targeted object: may need to specify the gameObject WhatToTarget
             * //ActionCombust.Burn();
             * WhatToTarget.GetComponent<"Combust">.Burn();
             * }
             * if(DesiredAction == Eat){
             * //should eat the targeted WhatToTarget
             * ActionEat.Eat();
             * }
             */
        }
    }