Question by
nu51313932 · Jan 17, 2017 at 04:43 PM ·
2drigidbody2dvelocityphysics2dclimb
Climbing code problem (2d physic).
Following this code from Youtube tutor.
void OnTriggerStay2D(Collider2D other)
{
if( other.tag == "ladder" && Input.GetKey(KeyCode.W))
{
rigid2d.velocity = new Vector2(0, 1.2f);
}
else
{
rigid2d.velocity = new Vector2(0, 0.32f);
}
if (other.tag == "ladder" && Input.GetKey(KeyCode.S))
{
rigid2d.velocity = new Vector2(0, -1.2f);
}
}
Picture: https://www.img.in.th/images/7a0f8bd9a3d755450951cd5f90663af4.png
When I moving up or down and stop for awhile and try to move up or down again (move up or down by using key W or S). It won't move unless I move left or right before move up or down again. How to solve this?
Comment