示例#1
0
    public void Movement()
    {
        if (!_target || reachedEndOfPath)
        {
            return;
        }
        _animationScript.Move(true);

        float distanceFromPath = Vector2.Distance(_rb.position, path.vectorPath[currentWayPoint]);

        if ((distanceFromPath <= nextWayPointDistance)) // burda eger yolu tamamladiysak devam etmeye calisma diyoruz.
        {
            currentWayPoint++;
            _movementDirection = DirectionCalculator();
            RotateEnemy(_movementDirection);
        }
        _movementDirection = DirectionCalculator();

        _rb.MovePosition(_rb.position + _movementDirection * speed * Time.fixedDeltaTime);
    }
示例#2
0
    public virtual void Move()
    {
        if (Alive)
        {
            if (!Attacking)
            {
                if (isHit == false)
                {
                    //get x and y differences between this and player
                    //whichever one is larger, move in that direction (so it doesn't move directly diagonal
                    //needs to be a way to handle if the distances are exactly equal, if so favour x over y movement

                    //if moving
                    Vector3 posDif = transform.position - playerPosition;
                    if (playerPosition.x > transform.position.x) //if player is on right of enemy
                    {
                        flip = true;
                    }
                    else
                    {
                        flip = false;
                    }

                    if ((Vector3.Distance(transform.position, playerPosition)) <= aggroDistance)
                    {
                        if ((Vector3.Distance(transform.position, playerPosition)) <= 1.5f) //if in attacking range
                        {
                            Attack();
                        }
                        else    //if out of attacking range
                        {
                            _enemyAnim.GetAnimator().SetBool("InCombat", false);
                        }


                        if ((Mathf.Abs(transform.position.x - playerPosition.x)) >= Mathf.Abs((transform.position.y - playerPosition.y))) // if the distance between the x components is larger than the y components
                        {
                            posDif.y           = transform.position.y;                                                                    //basically, moving in a straight line horizontally
                            posDif.x           = playerPosition.x;
                            transform.position = Vector3.MoveTowards(transform.position, posDif, speed * Time.deltaTime);
                            _enemyAnim.Move(0.2f);
                        }
                        else //if the distance between the y components is larger than the x components
                        {
                            posDif.x           = transform.position.x; //basically, moving in a straight line vertically
                            posDif.y           = playerPosition.y;
                            transform.position = Vector3.MoveTowards(transform.position, posDif, speed * Time.deltaTime);
                            _enemyAnim.Move(0.2f);
                        }



                        //transform.position = Vector3.MoveTowards(transform.position, playerPosition, speed * Time.deltaTime);
                        //_enemyAnim.Move(0.2f);
                    }
                    else //meaning, out of range
                    {
                        _enemyAnim.GetAnimator().SetBool("InCombat", false);
                        _enemyAnim.Move(0);
                    }
                }
                Flip();
                //else, _enemyAnim.Move(0)
            }
        }
    }