Example #1
0
    private void Movement(Vector3 nextPosition)     //nextPosition is the current position(before being challenged)
    {
        challenged = detectPlayer.PlayerDetected();

        if (challenged)
        {
            directionOfPlayer = (Player.transform.position - transform.position).normalized;
            rb.MovePosition(transform.position + directionOfPlayer * attackSpeed * Time.deltaTime);
        }
        else
        {
            Vector3 directionOfNextPosition = (nextPosition - transform.position).normalized;
            if (Vector3.Distance(transform.position, nextPosition) < .05)
            {
                transform.position = nextPosition;
            }
            else
            {
                rb.MovePosition(transform.position + directionOfNextPosition * normalSpeed * Time.deltaTime);
            }
        }
        //if ((tempPosition.x - transform.position.x) > 0 && !facingRight) //flips the animation to face right
        //{
        //    Flip();
        //}
        //else if ((tempPosition.x - transform.position.x) < 0 && facingRight) //flips the animation to face left
        //{
        //    Flip();
        //}
    }
 private void Update()
 {
     challenged = detectPlayer.PlayerDetected();             //update challenged boolean every frame
 }
Example #3
0
 private void Update()
 {
     challenged = detectPlayer.PlayerDetected();
 }