https://www.udemy.com/course/unitycourse/learn/lecture/28740552#content
The player is not climbing the ladder. I even put a debug.log to check moveinput.y
https://www.udemy.com/course/unitycourse/learn/lecture/28740552#content
Hi @Paper_Nerves,
Welcome to our community!
Please note, it’s better to copy/paste your code and apply the code fencing characters, rather than using screenshots. Screenshots are ideal for displaying specific details from within a game engine editor or even error messages, but for code, they tend to be less readable, especially on mobile devices which can require extensive zooming and scrolling.
You also prevent those that may offer to help you the ability to copy/paste part of your code back to you with suggestions and/or corrections, meaning that they would need to type a potentially lengthy response. You will often find that people are more likely to respond to your questions if you make it as easy as possible for them to do so.
Regarding the Debug.Log in your code, what was the output in your console? Was it the expected output?
Also make sure that the ladder has got the exact physics shape as shown by Rick. If your physics shape is different, it might be that his solution won’t work for you.
Hope this helps.
See also:
Thank you for replying .
The sprite for the ladder is the exact same as given by Rick.
And this the copy pasted code for reference.
The debug.log always gives output for moveinput.y as 1 when pressed and 0 when not pressed
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMovement : MonoBehaviour
{
[SerializeField] float runSpeed = 10f;
[SerializeField] float jumpSpeed = 3f;
[SerializeField] float climbSpeed = 3f;
Vector2 moveInput;
Rigidbody2D myRigidbody;
CapsuleCollider2D myCapsuleCollider;
Animator myAnimator;
void Start()
{
myRigidbody = GetComponent<Rigidbody2D>();
myAnimator = GetComponent<Animator>();
myCapsuleCollider = GetComponent<CapsuleCollider2D>();
}
void Update()
{
Run();
FlipSprite();
ChangeRunningAnimationState();
ClimbLadder();
Debug.Log(moveInput.y);
}
private void FlipSprite()
{
bool playerHasHorizontalSpeed = Mathf.Abs(myRigidbody.velocity.x) > Mathf.Epsilon;
if (playerHasHorizontalSpeed)
{
transform.localScale = new Vector2(Mathf.Sign(myRigidbody.velocity.x), 1f);
}
}
void OnMove(InputValue value)
{
moveInput = value.Get<Vector2>();
Debug.Log(moveInput);
}
void Run()
{
Vector2 playerVelocity = new Vector2 (moveInput.x * runSpeed, myRigidbody.velocity.y );
myRigidbody.velocity = playerVelocity;
}
void OnJump(InputValue value)
{ if (myCapsuleCollider.IsTouchingLayers(LayerMask.GetMask("Ground")))
{
if(value.isPressed)
{
myRigidbody.velocity += new Vector2(0f, jumpSpeed);
}
}
}
void ChangeRunningAnimationState()
{
if (Mathf.Abs(myRigidbody.velocity.x) > Mathf.Epsilon)
{
myAnimator.SetBool("isRunning", true);
}
else
{
myAnimator.SetBool("isRunning", false);
}
}
void ClimbLadder()
{
if (myCapsuleCollider.IsTouchingLayers(LayerMask.GetMask("Ladder")))
{
Vector2 climbVelocity = new Vector2(myRigidbody.velocity.x, moveInput.y * climbSpeed);
myRigidbody.velocity = climbVelocity;
}
}
}
Thank you for your help thus far.
Ok No problem I found the solution from this forum.
Having issues applying a custom physics shape to your sprite - possible solution.
I had forgot to tick used by composite and add a tilemap collider.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.