Hi.
I made a 2d game and wrote an script for climb the wall that work very well. in my game I have two wall and want with below script after RayCast collide to edge of each wall, set player (x,y) position to edge of wall. like below picture.
Debug.DrawLine (ClimbWall_Start.position, ClimbWall_End.position, Color.blue);
if (anim.GetCurrentAnimatorStateInfo (0).IsName ("LongJump") && IsGrounded == false)
{
if (Physics2D.Linecast (ClimbWall_Start.position, ClimbWall_End.position, 1 << LayerMask.NameToLayer ("Ground")))
{
if (GetWall == false)
{
GetWall = true;
rb.gravityScale = 0f;
rb.velocity = Vector2.zero;
anim.Play ("GetWall");
moveleft = 0;
moveright = 0;
if (FaceIsRight == true)
{
transform.position = new Vector2 (GameObject.FindGameObjectWithTag("Ground").transform.position.x - GetComponent<BoxCollider2D>().bounds.size.x, GameObject.FindGameObjectWithTag("Ground").transform.position.y + 0.1f);
}
else if (FaceIsLeft == true)
{
transform.position = new Vector2 (GameObject.FindGameObjectWithTag("Ground").transform.position.x + GetComponent<SpriteRenderer>().bounds.size.x , GameObject.FindGameObjectWithTag("Ground").transform.position.y + 0.1f);
}
}
}
}
but problem is when I cross the first wall, when I try to get second wall, player move to first wall and I can’t cross from second wall.
if possible please tell me where is the problem.
Thanks.