Hey there,
After implementing the Climb functionality I’ve noticed that the Jump has stopped working.
I don’t see this happening for Rick.
I’ve implemented some thing a bit differently (might be relevant, might not be).
The if statement before the jump is commented out so that nothing inhibits the jump functionality while debugging.
Here’s my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMovement : MonoBehaviour
{
[SerializeField] float runSpeed = 5f;
[SerializeField] float jumpSpeed = 5f;
[SerializeField] float climbSpeed = 5f;
SpriteRenderer playerSprite = new SpriteRenderer();
Vector2 moveInput;
Rigidbody2D playerRB2D; //- rick did it this way.
Animator characterAnimator = new Animator();
BoxCollider2D playerCapsuleCollider;
void Start()
{
playerRB2D = GetComponent<Rigidbody2D>();
characterAnimator = GetComponent<Animator>();
playerSprite = GetComponent<SpriteRenderer>();
}
void Update()
{
Climb();
Run();
FlipCharacter();
}
void OnMove(InputValue moveButton) //was “clickedButton”
{
moveInput = moveButton.Get<Vector2>();
}
void OnJump(InputValue jumpButton)
{
//if (!playerCapsuleCollider.IsTouchingLayers(LayerMask.GetMask("Ground"))) { return;}
if (jumpButton.isPressed)
{
playerRB2D.velocity += new Vector2 (0f, jumpSpeed);
}
}
void Climb()
{
Vector2 climbVelocity = new Vector2 (playerRB2D.velocity.x, moveInput.y * climbSpeed);
playerRB2D.velocity = climbVelocity;
}
void Run()
{
Vector2 playerVelocity = new Vector2 (moveInput.x * runSpeed, playerRB2D.velocity.y);
playerRB2D.velocity = playerVelocity;
if (playerVelocity.x !=0)
{
characterAnimator.SetBool ("isRunning", true);
}
else
{
characterAnimator.SetBool ("isRunning", false);
}
}
void FlipCharacter()
{
if (playerRB2D.velocity.x > 0)
{
playerSprite.flipX = false;
}
if (playerRB2D.velocity.x < 0)
{
playerSprite.flipX = true;
}
}
}