Exemplo n.º 1
0
        public override void OnEnter()
        {
            agent.stoppingDistance = 0.0f;

            if (patrolController?.targetWaypoint == null)
            {
                patrolController?.FindNextWaypoint();
            }

            if (patrolController?.targetWaypoint != null)
            {
                Vector3 destination = patrolController.targetWaypoint.position;
                agent?.SetDestination(destination);
                animator?.SetBool(hashMove, true);
            }
        }
Exemplo n.º 2
0
        public override void OnEnter()
        {
            agent.stoppingDistance = context.AttackRange;
            agent?.SetDestination(context.Target.position);

            animator?.SetBool(isMovehash, true);
        }
Exemplo n.º 3
0
            //////////////////////////////////////////////////////////////////////////////
            //                                                                          //
            //Unity Functions                                                           //
            //                                                                          //
            //////////////////////////////////////////////////////////////////////////////
            // Use this for initialization
            void Start()
            {
                transform.position = Vector3.zero;

                navMeshAgent = GetComponent<NavMeshAgent>();

                Vector3 destination = Random.insideUnitSphere * 35;
                destination.y = 0;
                navMeshAgent.SetDestination(destination);

                speed = Random.Range(0.75f, 1.25f);
            }
Exemplo n.º 4
0
    private void Update()
    {
        if (PhotonNetwork.IsMasterClient)
        {
            if (_agent.enabled)
            {
                _agent?.SetDestination(_agentDestination);
            }

            transform.position = _agent.transform.position;
            transform.rotation = _agent.transform.rotation;
            if (isManual)
            {
                _agentDestination = transform.position;
            }
        }
    }
Exemplo n.º 5
0
 private void Update()
 {
     if (agent.remainingDistance > agent.stoppingDistance)
     {
         character.Move(agent.desiredVelocity, false, false);
     }
     else
     {
         if (waypoints.Count > 0)
         {
             agent?.SetDestination(waypoints.Dequeue());
         }
         else
         {
             character.Move(Vector3.zero, false, false);
         }
     }
 }
Exemplo n.º 6
0
    private void Update()
    {
        // Ensure Target exists
        if (Target == null)
        {
            return;
        }

        // Ensure Target has moved
        if (Target.position == _previousTargetPosition && _agent.hasPath)
        {
            return;
        }

        // Update previous target position
        _previousTargetPosition = Target.position;

        // Update NavMeshAgent's destination
        _agent?.SetDestination(Target.position);
    }
Exemplo n.º 7
0
    private IEnumerator UpdatePath()
    {
        const float refreshRate = .25f;

        while (_hasTarget)
        {
            if (_currentState == State.Chasing)
            {
                Vector3 dirToTarget = (_target.position - transform.position).normalized;
                Vector3 targetPos   = _target.position - dirToTarget * (_myCollisionRadius + _targetCollisionRadius + _attackDistanceThreshold / 2);

                if (!Dead)
                {
                    _pathFinder?.SetDestination(targetPos);
                }
            }

            yield return(new WaitForSeconds(refreshRate));
        }
    }
    protected override void Run()
    {
        GameObject agentToKill = this.parentObject.gameObject.GetComponent <OtherAgentTracker>().GetClosestKillableAgent();

        if (Vector3.Distance(this.parentObject.transform.position, agentToKill.transform.position) < KillRange)
        {
            agentToKill.GetComponent <TaskProcessor>().IsDead = true;
            hasKilled = true;
            TaskName  = $"Killed: {agentToKill.name}";
            var splat = GameObject.Instantiate(this.parentObject.gameObject.GetComponent <OtherAgentTracker>().Splat);
            splat.transform.position = new Vector3(agentToKill.transform.position.x, -0.49f, agentToKill.transform.position.z);
            agentToKill.SetActive(false);
            this.parentObject.gameObject.GetComponent <OtherAgentTracker>().TimeSinceKill = 0;
            this.parentObject.gameObject.GetComponent <OtherAgentTracker>().SignalKillToUI(agentToKill.name);
        }
        else
        {
            NavMeshAgent agent = this.parentObject.GetComponent <NavMeshAgent>();
            agent?.SetDestination(agentToKill.transform.position);
        }
    }
Exemplo n.º 9
0
    // Update is called once per frame
    void Update()
    {
        distance = Vector3.Distance(transform.position, player.transform.position);
        if (distance <= distanceDetected && seePlayer == false)
        {
            state = States.playerDetected;
        }
        else if (seePlayer == false)
        {
            state = States.playerUndetected;
        }
        if (seePlayer == true)
        {
            state = States.playerSeen;
        }
        switch (state)
        {
        //Déplacement aléatoire, définir un comportement
        case States.playerUndetected:
            if (searchingNewPoint == true)
            {
                if (randomPoint(transform.position, range, out point))
                {
                    searchingNewPoint = false;
                    destination       = point;
                    Debug.DrawRay(point, Vector3.up, Color.blue, 50f);
                }
            }
            if (agent.remainingDistance <= 1)
            {
                searchingNewPoint = true;
            }
            break;

        case States.playerDetected:
            Vector3    direction = player.transform.position - transform.position;
            float      angle     = Vector3.Angle(direction, transform.forward);
            RaycastHit hit;
            if (Physics.Raycast(transform.position, direction.normalized, out hit, distanceDetected))
            {
                if (hit.collider.gameObject == player)
                {
                    seePlayer = true;
                    state     = States.playerSeen;
                }
                else
                {
                    transform.LookAt(player.transform.position);
                    if (searchingNewPoint == true)
                    {
                        if (randomPoint(transform.position, range, out point))
                        {
                            searchingNewPoint = false;
                            destination       = point;
                            Debug.DrawRay(point, Vector3.up, Color.blue, 50f);
                        }
                    }
                    if (agent.remainingDistance <= 1)
                    {
                        searchingNewPoint = true;
                    }
                }
            }
            break;

        case States.playerSeen:        // complétement à refaire
            Vector3 lastPositionPlayer;
            direction = player.transform.position - transform.position;
            if (Physics.Raycast(transform.position, direction.normalized, out hit, distanceDetected))
            {
                if (hit.collider.gameObject == player)
                {
                    lastPositionPlayer = player.transform.position;
                    destination        = lastPositionPlayer;
                }
            }
            if (agent.remainingDistance <= 1)
            {
                state = States.playerUndetected;
            }
            break;
        }

        Debug.Log(point);
        Debug.Log(destination);
        agent.SetDestination(destination);
    }
Exemplo n.º 10
0
 public void Move(Vector3 destination)
 {
     navAgent?.SetDestination(destination);
 }
Exemplo n.º 11
0
    //end setting states



    //Movement handeling and navigation
    public void Move(Vector3 position)
    {
        navAgent.SetDestination(position);
    }
Exemplo n.º 12
0
 void SetMoveTarget(Vector3 movePosition)
 {
     navMesh.SetDestination(movePosition);
 }
Exemplo n.º 13
0
    private void Update()
    {
        if (gameManager.gameStarted && !active)
        {
            active = true;
            animator.SetBool("run", true);

            ParticleSystem.EmissionModule em = traileFx.emission;
            em.enabled = true;

            if (isAI)
            {
                agent.enabled = true;
            }
        }


        if (active)
        {
            if (isAI)
            {
                if (!stunned)
                {
                    if (gameManager.playersInZone.Contains(transform))
                    {
                        target = GetClosestEnemyInZone(gameManager.playersInZone);
                        if (target == null)
                        {
                            target = zoneScript.wayPoints[UnityEngine.Random.Range(0, zoneScript.wayPoints.Length)];
                        }
                    }
                    else
                    {
                        target = GetClosestEnemyInZone(gameManager.players);
                        if (Vector3.Distance(transform.position, target.position) > outsideOfZoneRange)
                        {
                            target = zone;
                        }
                    }
                    agent.SetDestination(target.position);
                }
            }
            else
            {
                if (Input.GetMouseButton(0))
                {
                    Vector3 touchMagnitude = new Vector3(CnInputManager.GetAxis("Horizontal"), CnInputManager.GetAxis("Vertical"), 0);
                    Vector3 touchPosition  = transform.position + touchMagnitude.normalized;
                    Vector3 touchDirection = touchPosition - transform.position;
                    float   angle          = Mathf.Atan2(touchDirection.y, touchDirection.x) * Mathf.Rad2Deg;
                    angle -= 90;
                    Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.down);
                    transform.rotation = Quaternion.Lerp(transform.rotation, rotation, turnSpeed * Mathf.Min(Time.deltaTime, .04f));
                }
            }

            if (transform.position.y < -1 && !stunned)
            {
                ParticleSystem.EmissionModule emission = traileFx.emission;
                emission.enabled = false;
                stunned          = true;
                speed            = 0;
                StartCoroutine(Dead());
            }
        }
    }
Exemplo n.º 14
0
    private void Update()
    {
        Vector3 targetDir = player.transform.position - transform.position;

        targetDir = targetDir.normalized;
        float dot = Vector3.Dot(targetDir, transform.forward);

        angle = Mathf.Acos(dot) * Mathf.Rad2Deg;
        float distPlayer = Vector3.Distance(player.transform.position, transform.position);

        RaycastHit hit;

        if (Physics.Raycast(transform.position, targetDir, out hit))
        {
            if (hit.transform.gameObject.CompareTag("Player"))
            {
                playerVisible = true;
            }
            else
            {
                playerVisible = false;
            }
        }

        if (distPlayer <= targetRange && angle <= viewAngle / 2 && distPlayer > attackRange && playerVisible)
        {
            idle                = false;
            targeting           = true;
            myNMagent.isStopped = false;
            myNMagent.speed     = targetingSpeed;
            myNMagent.SetDestination(plLastKnownLoc);
        }
        else if (distPlayer <= attackRange && angle <= viewAngle / 2 && distPlayer > detectRange && playerVisible)
        {
            idle                = false;
            targeting           = true;
            myNMagent.isStopped = false;
            myNMagent.speed     = targetingSpeed;
            transform.LookAt(player.transform.position);
            arm.transform.LookAt(player.transform.position);
            myNMagent.SetDestination(player.transform.position);
        }
        else if (distPlayer <= detectRange && distPlayer > minRange && playerVisible)
        {
            idle                = false;
            targeting           = true;
            myNMagent.isStopped = false;
            myNMagent.speed     = targetingSpeed;
            transform.LookAt(player.transform.position);
            arm.transform.LookAt(player.transform.position);
            myNMagent.SetDestination(player.transform.position);
        }
        else if (distPlayer <= minRange && playerVisible)
        {
            idle                = false;
            targeting           = true;
            myNMagent.isStopped = false;
            myNMagent.speed     = targetingSpeed;
            transform.LookAt(player.transform.position);
            arm.transform.LookAt(player.transform.position);
            plLastKnownLoc = player.transform.position;
            myNMagent.SetDestination(plLastKnownLoc);
        }
        else
        {
            if (gotShot)
            {
                //Debug.Log("GOTSHOT");
                myNMagent.isStopped = false;
                transform.LookAt(player.transform.position);
                arm.transform.LookAt(player.transform.position);
                plLastKnownLoc = player.transform.position;
                myNMagent.SetDestination(plLastKnownLoc);
                searchPos = plLastKnownLoc;
                searching = true;
                gotShot   = false;
                idle      = false;
            }

            if (targeting)
            {
                targeting = false;
                makeIdle();
            }
        }

        if (searching && Vector3.Distance(transform.position, searchPos) < 0.5f)
        {
            //Debug.Log("op searchpos");
            searching           = false;
            headingBack         = true;
            myNMagent.isStopped = false;
            myNMagent.SetDestination(startpos);
            //if (points != null)
            //{
            //    GotoNextPoint();
            //}
            //else
            //{
            //    myNMagent.SetDestination(startpos);
            //}
        }

        // Choose the next destination point when the agent gets
        // close to the current one.
        if (!myNMagent.pathPending && myNMagent.remainingDistance < 0.5f && idle)
        {
            //Debug.Log("checknextpoint");
            if (points.Length > 0)
            {
                GotoNextPoint();
            }
        }
        if (idle && Vector3.Distance(idlePos, transform.position) < 0.5f)
        {
            //Debug.Log("op punt van bestemming idle");
            //kan glitchen als enemy patrollt en dan te dicht bij dat punt komt
            //dan idlePos naar een heeeel ver punt zetten na gotonextpoint of setdestination
            if (points.Length > 0)
            {
                GotoNextPoint();
            }
            else
            {
                myNMagent.isStopped = false;
                myNMagent.SetDestination(startpos);
                headingBack = true;
                idle        = false;
            }
        }
        else if (headingBack && Vector3.Distance(startpos, transform.position) < 0.5f)
        {
            myNMagent.isStopped = true;
            headingBack         = false;
            idle = true;
            //Debug.Log("STOP");
        }

        if (hp <= 0)
        {
            Instantiate(deathParticle, transform.position, Quaternion.identity);
            GameObject.FindGameObjectWithTag("GH").GetComponent <ScoreSystem>().AddPoints(10f);
            float random = Random.value;
            Debug.Log(random.ToString());
            if (random <= 0.2f)
            {
                Instantiate(hpPickup, transform.position, Quaternion.identity);
            }
            Destroy(this.gameObject);
        }

        if (targeting)
        {
            if (timeBTWShots <= 0 && distPlayer <= attackRange)
            {
                timeBTWShots = startTimeBTWShots;
                GameObject bullet = Instantiate(Bullet, shotPoint.transform.position, shotPoint.transform.rotation);
                bullet.GetComponent <EnemyBullet>().damage = damage;
            }
            else
            {
                timeBTWShots -= Time.deltaTime;
            }
        }

        if (plLastKnownLocTime <= 0)
        {
            plLastKnownLocTime = plLastKnownLocStartTime;
            plLastKnownLoc     = player.transform.position;
        }
        else
        {
            plLastKnownLocTime -= Time.deltaTime;
        }
    }
 public void MakeWayPath()
 {
     _agent?.SetDestination(_currentPoint);
 }
Exemplo n.º 16
0
 // Use this for initialization
 void Start()
 {
     agent = GetComponent <NavMeshAgent> ();
     agent.SetDestination(destination);
 }
Exemplo n.º 17
0
 // Update is called once per frame
 void Update()
 {
     agent.SetDestination(player.transform.position);
 }
    // Update is called once per frame
    public new void Update()
    {
        //Set UI
        healthSlider.value = health / healthMax * 100;
        healthText.text    = health + " / " + healthMax;

        //Dying
        if (health <= 0)
        {
            gameObject.SetActive(false);
        }

        //Set Target to player
        if (target == null)
        {
            target = GameObject.FindGameObjectWithTag("Player");
        }

        //Only do stuff when not kinematic
        if (rb.isKinematic)
        {
            myAnimator.speed = 0;
        }
        else
        {
            myAnimator.speed = 1;
            if (!HitState())
            {
                if (myState == states.walking)
                {
                    applyRootMotion = false;
                    if (target != null)
                    {
                        navMeshAgent.SetDestination(target.transform.position);
                    }
                    myAnimator.Play("Walk");
                    if (!isRanged)
                    {
                        if (Vector3.Distance(transform.position, target.transform.position) < 1)
                        {
                            myState = states.attackingMelee;
                        }
                    }
                    else
                    {
                        if (Vector3.Distance(transform.position, target.transform.position) < 10)
                        {
                            myState = states.attackingRange;
                        }
                    }
                }
                if (myState == states.attackingMelee)
                {
                    if (!attackStarted)
                    {
                        attackTimer         = myAnimClips[attackCounter].length;
                        currentAttackLength = myAnimClips[attackCounter].length;
                        applyRootMotion     = true;
                        myAnimator.Play(myAnimClips[attackCounter].name);
                        MeleeProperties.instance.GetProperties(myAnimClips[attackCounter].name, GetComponent <BaseCharacter>(), false);
                        attackStarted = true;
                        if (attackCounter < myAnimClips.Length - 1)
                        {
                            attackCounter += 1;
                        }
                        else
                        {
                            attackCounter = 0;
                        }
                    }
                    else
                    {
                        attackTimer -= Time.deltaTime;
                        if (attackTimer <= 0)
                        {
                            attackStarted = false;
                            if (!(Vector3.Distance(transform.position, target.transform.position) < 1))
                            {
                                myState = states.walking;
                            }
                        }
                    }
                }
                if (myState == states.attackingRange)
                {
                    if (!rangedAttackStarted)
                    {
                        if (Physics.Raycast(transform.position + Vector3.up, transform.forward, 1000, 1 << 11))
                        {
                            Bullet bullet = Instantiate(bulletPrefab, transform.position + Vector3.up + transform.forward, Quaternion.identity).GetComponent <Bullet>();
                            bullet.transform.localScale = bullet.transform.localScale * bulletSize;
                            bullet.myVelocity           = transform.forward * bulletSpeed;
                            rangedAttackStarted         = true;
                            rangedAttackTimer           = 2;
                            myAnimator.Play("PistolShooting");
                        }
                    }
                    else
                    {
                        rangedAttackTimer -= Time.deltaTime;
                        if (rangedAttackTimer <= 0)
                        {
                            rangedAttackStarted = false;
                            myAnimator.Play("Idle");
                        }
                    }
                }
            }
            else
            {
                applyRootMotion = false;
            }
        }
    }
Exemplo n.º 19
0
    public virtual void boidMove(float speed, GameObject player, GameObject startGameObject, GameObject blood, GameObject bloodSplat) // boid speed, player, Gameobject to move to when reverting to wander, blood particle, blood png
    {
        distanceWanted = 10;                                                                                                          // Distance wanted between gameobjects


        foreach (GameObject boids in listOfBoids.ToArray())                                      // To array - allows me to dynamically remove objects while the loop is running
        {
            agent = boids.GetComponent <NavMeshAgent>();                                         // Gets navmesh agent component

            if (Vector3.Distance(boids.transform.position, destination) < 2 && fleeing == false) // If distance betweeen waypoint and boid is below 2 units
            {
                wander(boids);                                                                   // move to next waypoint
            }

            if (Vector3.Distance(boids.transform.position, player.transform.position) < 80 && fleeing == false) // If the player come within a distance of 80 units
            {
                fleeing = true;
                flee(player, boids);                                                                           // flle from player
            }
            if (Vector3.Distance(boids.transform.position, player.transform.position) > 80 && fleeing == true) // if distance between boids and enemy is  greater than 80 units, move back to starting waypoint
            {
                fleeing     = false;
                destination = startGameObject.transform.position;
            }


            //Debug.Log(Vector3.Distance(boids.transform.position, destination));
            // boids.transform.position = Vector3.Slerp(boids.transform.position, randomDestination, speed * Time.deltaTime);
            //boids.transform.eulerAngles = Vector3.Slerp(transform.eulerAngles, randomDestination, Time.deltaTime * speed);
            // agent.SetDestination(randomDestination);



            agent.SetDestination(destination);// Move to destination - varies depending on current state

            // result = Vector3.Slerp(boids.transform.position, averageCenter, speed);
            boids.transform.LookAt(destination);                                                                                   // Rotate gaameobject to look at the player
            boids.transform.Rotate(0, 180, 0);                                                                                     // Correct the rotation
            boids.transform.position = Vector3.MoveTowards(boids.transform.position, averageCenter, Time.deltaTime * speed / 50f); // Move game objects centerpoint of flock
            //boids.GetComponent<NavMeshAgent>().SetDestination(averageCenter);


            averageCenter = new Vector3(0, 0, 0); // reset value


            foreach (GameObject relativeBoid in listOfBoids.ToArray())                                        // compares boids to each other
            {
                float distance = Vector3.Distance(boids.transform.position, relativeBoid.transform.position); // Gets distances between a boids and all its neighbours



                if (distance > 0 && distance < distanceWanted)  // If the distance between that boid is less than the distance wanted
                {
                    averageCenter = averageCenter + boids.transform.position;

                    Vector3 difference = relativeBoid.transform.position - boids.transform.position; // Gets the difference in position
                    difference.y = 0;                                                                // sets y axis to 0 as we do not want to adress that axis

                    difference = difference.normalized;                                              // Normalise difference

                    boids.GetComponent <Rigidbody>().AddForce(-difference * 10, ForceMode.Force);    // add force in the opposite direction to where the boids are moving towards.
                }
            }
            averageCenter = averageCenter / numberOfAnimals; // sets average center value
            DestroyPrey(boids, player, blood, bloodSplat);   // destroy boid function
        }
    }
Exemplo n.º 20
0
    // Update is called once per frame
    void Update()
    {
        //distancefromPlayer = Vector3.Distance(transform.position, target.transform.position);
        //Debug.Log(distancefromPlayer);

        if (timeuntilleavingPuddle >= 20.0f)
        {
            GameObject lavapuddleClone = Instantiate(lavaPuddle, lavapuddlePlacement.position, transform.rotation);
            Transform  puddleSpot      = lavapuddleClone.transform;
            lavapuddleClone.transform.localScale += new Vector3(2.0f, 0.0f, 2.0f);
            lavapuddleClone.transform.parent      = null;
            lavapuddleClone.transform.SetParent(puddleSpot);
            timeuntilleavingPuddle = 0.0f;
        }

        switch (fAI)
        {
        case FireAI.Run:
            nmAgent.speed     = speed;
            nmAgent.isStopped = false;
            nmAgent.SetDestination(target.transform.position);
            distancefromPlayer = Vector3.Distance(transform.position, target.transform.position);
            if (distancefromPlayer <= attackRange)
            {
                setState(FireAI.attack1);
            }
            else
            {
                timeuntilleavingPuddle += 0.01f;
                //Debug.Log(timeuntilleavingPuddle);
            }
            if (health <= 0.0f)
            {
                setState(FireAI.death2);
            }
            break;

        case FireAI.attack1:
            nmAgent.isStopped = true;
            nmAgent.speed     = 0;
            ++temperature;
            Debug.Log(temperature);
            if (temperature >= 400f)
            {
                Destroy(gameObject);
                distancefromPlayer = Vector3.Distance(transform.position, target.transform.position);
                if (distancefromPlayer <= 5f)
                {
                    target.GetComponent <PlayerHealth>().changeHealth(enemyDamage);
                }
            }
            distancefromPlayer = Vector3.Distance(transform.position, target.transform.position);
            if (distancefromPlayer > attackRange)
            {
                setState(FireAI.Run);
            }
            break;

        case FireAI.attack2:
            break;

        case FireAI.gethit:
            if (target.GetComponent <AR>())
            {
                health -= target.GetComponent <AR>().weaponDamage;
                if (health <= 0.0f)
                {
                    fAI = FireAI.death2;
                }
                break;
            }
            if (target.GetComponent <smg>())
            {
                health -= target.GetComponent <smg>().weaponDamage;
                if (health <= 0.0f)
                {
                    fAI = FireAI.death2;
                }
                break;
            }
            if (target.GetComponent <RocketLauncher>())
            {
                health -= target.GetComponent <RocketLauncher>().weaponDamage;
                if (health <= 0.0f)
                {
                    fAI = FireAI.death2;
                }
                break;
            }
            if (target.GetComponent <GrenadeLauncher>())
            {
                health -= target.GetComponent <GrenadeLauncher>().weaponDamage;
                if (health <= 0.0f)
                {
                    fAI = FireAI.death2;
                }
                break;
            }
            if (target.GetComponent <pistol>())
            {
                health -= target.GetComponent <pistol>().weaponDamage;
                if (health <= 0.0f)
                {
                    fAI = FireAI.death2;
                }
                break;
            }
            if (target.GetComponent <SniperRifle>())
            {
                health -= target.GetComponent <SniperRifle>().weaponDamage;
                if (health <= 0.0f)
                {
                    fAI = FireAI.death2;
                }
                break;
            }
            if (target.GetComponent <shotgun>())
            {
                health -= target.GetComponent <shotgun>().weaponDamage;
                if (health <= 0.0f)
                {
                    fAI = FireAI.death2;
                }
                break;
            }
            if (target.GetComponent <EnergyHammer>())
            {
                health -= target.GetComponent <EnergyHammer>().weaponDamage;
                if (health <= 0.0f)
                {
                    fAI = FireAI.death2;
                }
            }
            break;

        case FireAI.death1:
            break;

        case FireAI.death2:
            Destroy(gameObject);
            target.GetComponent <PlayerScore>().playerScore += target.GetComponent <PlayerScore>().pointsperKill;
            int randomnumber = Random.Range(0, 100);
            if (randomnumber % 4 == 0)
            {
                int randompowerup = Random.Range(0, 2);
                Instantiate(target.GetComponent <Arsenal>().powerups[randompowerup], transform.position, transform.rotation);
            }
            break;

        default:
            break;
        }
    }
Exemplo n.º 21
0
 private void GotoPosition(Vector3 position)
 {
     navMeshAgent.SetDestination(position);
 }
Exemplo n.º 22
0
 //Note that by having it only update once, the AI will only follow once it updates (not a constant follow)
 public void MoveToPosition(Vector3 targetPosition)
 {
     agent.SetDestination(targetPosition); //But by only updating once (as opposed to every frame) it is much less resource intensive.
 }
Exemplo n.º 23
0
    public void Move()
    {
        Debug.Log("Move spider");
        bool       moved = false;
        Plataforma now   = currentPlat;

        if (horizontal)
        {
            if (dir == 0)
            {
                if (currentPlat.rightPlat != null)
                {
                    moved = true;
                    currentPlat.entity = null;
                    agent.SetDestination(currentPlat.rightPlat.transform.position);
                    currentPlat = currentPlat.rightPlat;
                }
                else if (currentPlat.leftPlat != null)
                {
                    moved = true;
                    dir   = 1;
                    currentPlat.entity = null;
                    agent.SetDestination(currentPlat.leftPlat.transform.position);
                    currentPlat = currentPlat.leftPlat;
                }
            }
            else
            {
                if (currentPlat.leftPlat != null)
                {
                    moved = true;
                    currentPlat.entity = null;
                    agent.SetDestination(currentPlat.leftPlat.transform.position);
                    currentPlat = currentPlat.leftPlat;
                }
                else if (currentPlat.rightPlat != null)
                {
                    moved = true;
                    dir   = 0;
                    currentPlat.entity = null;
                    agent.SetDestination(currentPlat.rightPlat.transform.position);
                    currentPlat = currentPlat.rightPlat;
                }
            }
        }
        else
        {
            if (dir == 0)
            {
                if (currentPlat.topPlat != null)
                {
                    moved = true;
                    currentPlat.entity = null;
                    agent.SetDestination(currentPlat.topPlat.transform.position + offset);
                    currentPlat = currentPlat.topPlat;
                }
                else if (currentPlat.bottomPlat != null)
                {
                    dir = 1;
                    currentPlat.entity = null;
                    moved = true;
                    agent.SetDestination(currentPlat.bottomPlat.transform.position + offset);
                    currentPlat = currentPlat.bottomPlat;
                }
            }
            else
            {
                if (currentPlat.bottomPlat != null)
                {
                    moved = true;
                    currentPlat.entity = null;
                    agent.SetDestination(currentPlat.bottomPlat.transform.position + offset);
                    currentPlat = currentPlat.bottomPlat;
                }
                else if (currentPlat.topPlat != null)
                {
                    moved = true;
                    dir   = 0;
                    currentPlat.entity = null;
                    agent.SetDestination(currentPlat.topPlat.transform.position + offset);
                    currentPlat = currentPlat.topPlat;
                }
            }
        }
        if (moved)
        {
            if (currentPlat.entity != null)
            {
                Debug.Log("Set Destination now");
                //agent.SetDestination(now.transform.position + offset);
                now.entity = this.gameObject;
                if (currentPlat.entity.tag == "Player")
                {
                    Debug.Log("Spider kills Player");
                }
            }
            else
            {
                currentPlat.entity = this.gameObject;
                currentPlat.moved();
            }
        }
        else
        {
            dir = (dir + 1) % 2;
        }
    }
 public void OnMoveMessage(Vector3 destination)
 {
     agent.SetDestination(destination);
 }
Exemplo n.º 25
0
 void MoveToTarget(Transform transform)
 {
     navMeshAgent.SetDestination(transform.position);
     point    = transform;
     movement = true;
 }
Exemplo n.º 26
0
 public void SetNavDestination(Vector3 destination)
 {
     _navMeshAgent?.SetDestination(destination);
 }
Exemplo n.º 27
0
 // Update destination
 private void UpdateDestination()
 {
     // Set destination to current goal position
     agent.SetDestination(goal.position);
 }
Exemplo n.º 28
0
    private void OnTriggerStay(Collider colpollo)
    {
        if (colpollo.transform.tag.Equals("Player"))
        {
            //vector = destino - origen
            //direction = player.transform.position - this.transform.position;
            direction = player.transform.position - gameObject.transform.position;
            distance  = Vector3.Magnitude(direction);
            angle     = Vector3.Dot(gameObject.transform.forward, player.transform.position);



            playerInSight = false;
            float calculateAngle = Vector3.Angle(direction, gameObject.transform.forward);
            //Si el player está en el campo de visión
            if (calculateAngle < 0.5f * fieldOfViewAngle)
            {
                RaycastHit hit;
                if (DEBUG_DRAW)
                {
                    Debug.DrawRay(gameObject.transform.position + gameObject.transform.up,
                                  direction.normalized, Color.green);
                }
                //Trazo un rayo desde NPC hasta player
                if (Physics.Raycast(gameObject.transform.position + gameObject.transform.up, direction.normalized,
                                    out hit, colcav.radius))
                {
                    //Si lo primero que localiza el rayo es el jugador
                    if (hit.collider.gameObject == player)
                    {
                        playerInSight = true;
                    }
                }
            }

            //Si después de toda la comprobación anterior, el player está en FoV del NPC
            if (playerInSight && distance < 22.5)
            {
                nav.SetDestination(player.transform.position);
                CalculatePathLength(player.transform.position);

                isAndandoCA = true;
                animator.SetBool("AndarCA", true);
                animator.SetBool("SacarA", false);
            }

            if (distance < 23 && distance > 22.5 && sacar == 1 && playerInSight)
            {
                isSacarA = true;
                animator.SetBool("SacarA", true);
                animator.SetBool("Parado", false);
            }

            if (distance < 2.5 && playerInSight)
            {
                isAtacando = true;
                float n = Random.Range(0, 1);

                if (isSacarA)
                {
                    animator.SetBool("Atacar", true);
                    animator.SetBool("SacarA", false);
                    isSacarA = false;
                }

                if (isAndandoCA)
                {
                    animator.SetBool("Atacar", true);
                    animator.SetBool("AndarCA", false);
                    isAndandoCA = false;
                }
            }

            if (distance > 2.5 && distance < 3 && isAtacando && playerInSight)
            {
                isAtacando  = false;
                isAndandoCA = true;
                animator.SetBool("AndarCA", true);
                animator.SetBool("Atacar", false);
            }

            if (distance > 23.5f && distance < 25)
            {
                if (isAndandoCA)
                {
                    animator.SetBool("Parado", true);
                    animator.SetBool("AndarCA", false);
                    isAndandoCA = false;
                    isParado    = true;
                }

                if (isSacarA)
                {
                    animator.SetBool("Parado", true);
                    animator.SetBool("SacarA", false);
                    isSacarA = false;
                    isParado = true;
                }
            }

            if (!playerInSight)
            {
                animator.SetBool("SacarA", true);
                isSacarA = true;

                if (isAndandoCA)
                {
                    animator.SetBool("AndarCA", false);
                    isAndandoCA = false;
                }

                if (isMeterA)
                {
                    animator.SetBool("MeterA", false);
                    isMeterA = false;
                }

                if (isAtacando)
                {
                    animator.SetBool("Atacar", false);
                    isAtacando = false;
                }

                if (isParado)
                {
                    animator.SetBool("Parado", false);
                    isParado = false;
                }
            }
        }
    }
Exemplo n.º 29
0
 void Start()
 {
     agent       = GetComponent <NavMeshAgent>();
     agent.speed = speed;
     agent.SetDestination(Camera.main.transform.position);
 }
Exemplo n.º 30
0
    protected override void Run()
    {
        NavMeshAgent agent = this.parentObject.GetComponent <NavMeshAgent>();

        agent?.SetDestination(objectToGoTo.transform.position);
    }
 void Start()
 {
     agent.SetDestination(target[0].transform.position);
     animator.SetBool("idle", false);
     animator.SetBool("walk", true);
 }