Question by
Payaso_Prince · Aug 22, 2017 at 01:52 AM ·
scripting problem
Player keeps climbing when key isn't held down?
Hey guys. I can't figure this out for the life of me. I've put together 2 simple scripts for my player to climb ladders. The problem is the player keeps climbing without stopping until I push the up or down key.
// Ladder code
private void OnTriggerStay2D(Collider2D other)
{
if (other.tag == "Player")
{
player.onLadder = true;
}
}
private void OnTriggerExit2D(Collider2D other)
{
if (other.tag == "Player")
{
player.onLadder = false;
}
}
// Player script Code
Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
public float climbSpeed = 1f;
if(onLadder)
{
climbVelocity = input.y * climbSpeed;
if (input.y != 0)
{
gravity = 0;
velocity = new Vector3(velocity.x, climbVelocity, 0);
}
}
Comment
Doesn't look like you are checking to see if the player has let go of the key. you are saving the axis of the input but no doing anything with it except for climb, which is also defaulting at 1, not 0.
Can we see more of your player script to understand ?
I have an idea of the problem but I can't be sure without the full script.