public void ExitRope() { if (_player.onRope == gameObject) { _player.onRope = null; _player.transform.parent = null; _player.GetComponent <Collider2D>().isTrigger = false; _player.GetComponent <Rigidbody2D>().simulated = true; _player.GetComponent <Rigidbody2D>().velocity = Vector2.zero; _player.transform.rotation = Quaternion.Euler(0f, 0f, 0f); if (_rb.velocity.x >= 0) { _player.GetComponent <Rigidbody2D>().AddForce(_rb.velocity * 1.3f + new Vector2(1f, 2f), ForceMode2D.Impulse); } else { _player.GetComponent <Rigidbody2D>().AddForce(_rb.velocity * 1.3f + new Vector2(-1f, 2f), ForceMode2D.Impulse); } Destroy(_player.GetComponent <Joint2D>()); bool leftFoot = _playerJump.GetGrounded(true); bool rightFoot = _playerJump.GetGrounded(false); if (leftFoot && rightFoot) { ClimbAnimation.SetTrigger("Land"); } else { ClimbAnimation.SetTrigger("Jump"); } ClimbAnimation.ResetTrigger("Climbing"); ClimbAnimation.speed = 1f; } }
public void MoveAnalog(float moveX, float moveY) { Animation.SetFloat("XMovement", Mathf.Abs(moveX)); //Apply the velocity of the player if (_player.onRope == null) { if (_player.onLadder) { bool leftFoot = _jump.GetGrounded(true); bool rightFoot = _jump.GetGrounded(false); if (!leftFoot && !rightFoot) { Animation.ResetTrigger("Jump"); Animation.SetTrigger("Climbing"); Animation.SetFloat("ClimbingSpeed", Mathf.Abs(moveY)); Animation.speed = Animation.GetFloat("ClimbingSpeed"); } else { Animation.ResetTrigger("Climbing"); Animation.SetTrigger("Land"); Animation.speed = 1f; } //ClimbAnimation.SetFloat("YMovement", Mathf.Abs(moveY)); //Move player if on a ladder (allow horizontal movement) if (moveX == 0 && moveY == 0) { _rb.velocity = new Vector2(0, 0); _rb.isKinematic = true; } else { _rb.velocity = new Vector2(moveX * runSpeed / 2f, moveY * runSpeed); _rb.isKinematic = false; } } else { //Move player if not jumping in the air if (!_jump._inAir) { _rb.velocity = new Vector2(moveX * runSpeed, _rb.velocity.y); } } } //Call flip script to flip the character's sprite if (moveX > 0) { _flipScript.FlipSprite(false); } else if (moveX < 0) { _flipScript.FlipSprite(true); } }