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 Move()
 {
     MyRigidbody2D.AddForce(this.direction * speed);
     if (MyRigidbody2D.velocity == Vector2.zero)
     {
         TurnAround();
     }
 }
Exemple #3
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);
    }
    private void FixedUpdate()
    {
        velocity = MoveTowardsWaypoint();

        if (velocity != Vector2.zero)
        {
            MyRigidbody2D.MovePosition(velocity);
            Flip();
        }
    }
Exemple #5
0
    public void Move(float horizontalMove, float verticalMove)
    {
        if (!Attacking && !OnLadder)
        {
            MyRigidbody2D.velocity = new Vector2(horizontalMove * movementSpeed, MyRigidbody2D.velocity.y);
            AnimationManager.SetMovementSpeed(horizontalMove);

            if (horizontalMove > 0 && !FacingRight || horizontalMove < 0 && FacingRight)
            {
                Flip();
            }
        }

        if (OnLadder)
        {
            MyRigidbody2D.velocity = new Vector2(0f, verticalMove * climbSpeed);
            if (OnGround && horizontalMove != 0)
            {
                OnLadder = false;
            }
            if (OnGround)
            {
                AnimationManager.SetClimbSpeed(0f);
            }
            else
            {
                AnimationManager.SetClimbSpeed(verticalMove);
            }
        }

        if (!OnGround && MyRigidbody2D.velocity.y < 0)
        {
            AnimationManager.StartLand();
        }

        if (OnGround && Jumping)
        {
            Jumping = false;
            MyRigidbody2D.AddForce(new Vector2(0, jumpForce));
        }

        if (Digging)
        {
            AnimationManager.Dig();
        }

        if (Blocking)
        {
            shieldCollider.enabled = true;
        }
        else
        {
            shieldCollider.enabled = false;
        }
    }
 private void MoveToPoint(Vector2 v)
 {
     MyRigidbody2D.MovePosition(Vector2.MoveTowards(transform.position, v,
                                                    MovementSpeed * Time.deltaTime));
 }
Exemple #7
0
 public void RpcReset()
 {
     MyRigidbody2D.Sleep();
     pObj.ReturnToPool();
 }