I understand how the code works for climbing the ladder, but I am confused to how Rick actually climbs up and down the ladder in the game. There is no input system for climbing the ladder so what controls are used to climb?
Thanks.
I understand how the code works for climbing the ladder, but I am confused to how Rick actually climbs up and down the ladder in the game. There is no input system for climbing the ladder so what controls are used to climb?
Thanks.
Hi Cork_Emperor,
Welcome to our community! Enjoy the course and happy coding!
The ClimbLadder() method gets called each frame in the Update() method. The first code in that method is:
if (!myFeetCollider.IsTouchingLayers(LayerMask.GetMask("Climbing")))
{
// code
return;
}
This means: If the feet collider is not touching the “Climbing” layer, the method gets terminated. That’s what the return;
keyword does.
If the feet collider is touching the “Climbing” layer, the code after the if-block gets executed. And that’s the code which allows us to move the player along its y-axis:
Vector2 climbVelocity = new Vector2 (myRigidbody.velocity.x, moveInput.y * climbSpeed);
myRigidbody.velocity = climbVelocity;
Is this what you wanted to know?
See also:
Hello Nina,
Thank you for the explanation, but I was confused about the controls I use to climb up and down the ladder when I am in play mode. Using the up and down arrows on my keyboard does not move my character up and down the ladder, but I saw in the video that Rick can move up and down the ladder. Please let me know if that is a code problem, or if I forgot to put something in the input system?
Thank you
Have you already tried to add Debug.Logs to your code to see what is going on during runtime? Theoretically, pressing the WASD keys should trigger the OnMove() method. If A and S don’t change the value of moveInput
, there is very likely something wrong with the Move action in the Player Input Settings.
Yeah I tried Debug.logs. My code works after adding the gravity scale. Thank you for the advice!
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.