球员攀岩墙问题

时间:2015-07-07 03:40:57

标签: unity3d unityscript

基本上我想要的是,当我的球员掉下来并且靠近墙壁时,他可以跳跃并攀爬它,并且他也可以跳跃并移动X'轴在墙的相反方向。所以我制作了3个groundCheck游戏对象作为我的玩家变换的孩子,它们被设置在他的下方,一个在底部中心,一个在左下角,一个在右下角。然后我检查他是否与墙壁碰撞,地面上有这些功能:

   bool CheckDown()
      {
   if (Physics2D.OverlapCircle(groundCheck.position, 0.01f, whatIsGround))
           return true;
       else
           return false;
     }

   bool CheckGround()
   {


       if (Physics2D.OverlapCircle(groundCheck.position, 0.01f, whatIsGround))
           return true;
       if (Physics2D.OverlapCircle(groundCheck2.position, 0.01f, whatIsGround))
           return true;

       if (Physics2D.OverlapCircle(groundCheck3.position, 0.01f, whatIsGround))
           return true;
       else
           return false;
   }
   bool CheckWallLeft()
   {
       if (Physics2D.OverlapCircle(groundCheck3.position, 0.01f, whatIsGround))
           return true;


       else
           return false;
   }
   bool CheckWallRight()
   {
       if (Physics2D.OverlapCircle(groundCheck2.position, 0.01f, whatIsGround))
           return true;

       else
           return false;
   }

然后我使用这些布尔值确定玩家是否可以跳跃:

        if (CheckWallLeft() && !CheckWallRight())
        {                
            if (h > 0)
   GetComponent<Rigidbody2D>().velocity = new Vector2(h * speedHeight,   GetComponent<Rigidbody2D>().velocity.y);
        }
        if (!CheckWallLeft() && CheckWallRight())
        {               
            if (h < 0)
            {

                GetComponent<Rigidbody2D>().velocity = new Vector2(h * speedHeight, GetComponent<Rigidbody2D>().velocity.y);
            }
        }   
        if(!CheckGround())
        GetComponent<Rigidbody2D>().velocity = new Vector2(h * speedHeight, GetComponent<Rigidbody2D>().velocity.y);
        if (CheckDown()) {
            GetComponent<Rigidbody2D>().velocity = new Vector2(h * speedHeight, GetComponent<Rigidbody2D>().velocity.y); 
    }

H输入getAxis水平。但由于某种原因,只有当他摔倒并面向左侧的墙壁时才有效........在右边他可以在X轴上移动到墙壁方向,所以如果他不能摔倒继续按D.任何想法?

0 个答案:

没有答案