public void Move(float move, bool crouch, bool jump) { // Move the character GetComponent <Rigidbody2D>().velocity = new Vector2(move * maxSpeed, GetComponent <Rigidbody2D>().velocity.y); // If the input is moving the player right and the player is facing left... if (move > 0 && !facingRight) { // ... flip the player. facingRight = Flip.HorizontalFlip(transform, facingRight); } // Otherwise if the input is moving the player left and the player is facing right... else if (move < 0 && facingRight) { // ... flip the player. facingRight = Flip.HorizontalFlip(transform, facingRight); } // If the player should jump... if (jump) { // Add a vertical force to the player. GetComponent <Rigidbody2D>().AddForce(new Vector2(0f, jumpForce)); } }
/// <summary> /// Move the character by the specified move, wheter he is walking crouching or jumping. /// </summary> /// <param name="move">Move the character by the specified move value.</param> /// <param name="crouch">If set to <c>true</c> player is crouching. Movement must adapt to it</param> /// <param name="jump">If set to <c>true</c> player is jumping. Movement must adapt to it</param> public void Move(float move, bool crouch, bool jump) { // If crouching, check to see if the character can stand up if (!crouch && anim.GetBool("Crouch")) { // If the character has a ceiling preventing them from standing up, keep them crouching if (Physics2D.OverlapCircle(ceilingCheck.position, ceilingRadius, whatIsGround)) { crouch = true; } } // Set whether or not the character is crouching in the animator anim.SetBool("Crouch", crouch); HandlePlatform(); //only control the player if grounded or airControl is turned on if (grounded || airControl) { // Reduce the speed if crouching by the crouchSpeed multiplier move = (crouch ? move * crouchSpeed : move); // The Speed animator parameter is set to the absolute value of the horizontal input. anim.SetFloat("Speed", Mathf.Abs(move)); // Move the character GetComponent <Rigidbody2D>().velocity = new Vector2(move * maxSpeed, GetComponent <Rigidbody2D>().velocity.y); // If the input is moving the player right and the player is facing left... if (move > 0 && !facingRight) { // ... flip the player. facingRight = Flip.HorizontalFlip(transform, facingRight); } // Otherwise if the input is moving the player left and the player is facing right... else if (move < 0 && facingRight) { // ... flip the player. facingRight = Flip.HorizontalFlip(transform, facingRight); } } //if the player is mounted if (isMounted == true) { if (Input.GetKey(KeyCode.UpArrow)) //desmontar apertando up & jump //LEONARDO - DEVE HAVER UM AVISO NA TELA PARA QUE O JOGADOR SAIBA DISSO { if (Input.GetKeyDown(KeyCode.Space)) { isMounted = false; } } } //antes do pulo if (MovingPlatform != null) { _activeGlobalPlatformPoint = transform.position; _activeLocalPlatformPoint = MovingPlatform.transform.InverseTransformPoint(transform.position); //Debug.DrawLine(transform); } // If the player should jump... if (grounded && jump) { // Add a vertical force to the player. anim.SetBool("Ground", false); GetComponent <Rigidbody2D>().AddForce(new Vector2(0f, jumpForce)); } }