Exemple #1
0
 private void Wander()
 {
     if (wanderTimerState == 0)
     {
         wanderTimer += 0.1f * Time.deltaTime * wanderTimerSpeed;
         if (wanderTimer >= wanderTimerMax)
         {
             wanderTimer = 0;
             if (isMoving)
             {
                 int movDir = Random.Range(0, 8);
                 RandomizeAIDirection(movDir);
             }
             else if (isIdle)
             {
                 randomDirection.x = 0;
                 randomDirection.y = 0;
             }
         }
         // Movement
         float velocityX = randomDirection.x * Time.smoothDeltaTime * movementSpeed;
         float velocityY = randomDirection.y * Time.smoothDeltaTime * movementSpeed;
         //Debug.Log("VelocityX is " + velocityX);
         //Debug.Log("VelocityY is " + velocityY);
         if (MyAnimator != null)
         {
             MyAnimator.SetFloat("SpeedX", velocityX);
             MyAnimator.SetFloat("SpeedY", velocityY);
         }
         MyRigidbody2D.AddForceAtPosition(new Vector3(velocityX, velocityY, 0) * movementSpeed, transform.position);
     }
 }
Exemple #2
0
    private void MoveAwayPlayer()
    {
        Debug.Log("Moving away from player");
        Vector3 directionOfCharacter = Target.transform.position - transform.position;

        directionOfCharacter = directionOfCharacter.normalized;
        //Debug.Log(directionOfCharacter);
        MyRigidbody2D.AddForceAtPosition(directionOfCharacter * -1, transform.position);
    }