简体   繁体   English

Unity 2D:碰撞触发器

[英]Unity 2D: Collision trigger

So here it is, I am making a game for my thesis. The game is called hacky sack, I所以在这里,我am making a game for my thesis. The game is called hacky sack, I am making a game for my thesis. The game is called hacky sack, I am having a problem when my trigger is true because the collision for my character and the object is passing through and if idon`t have a trigger it was just basically hitting it even when my Player is running. am making a game for my thesis. The game is called hacky sack, I当我的触发器为真时我遇到了问题,因为我的角色和对象的碰撞正在通过,如果我没有触发器,即使我的播放器正在运行,它也只是基本上击中它。

And can you guys help me on how the Object/Sack going up randomly when it hit.你们能帮我看看 Object/Sack 在它击中时是如何随机上升的吗? So here is my code :所以这是我的代码:

 public void Sipa()
 {
   if (canSipa == true)
    {
     _pitcha.GetComponent<Rigidbody2D>().AddForce(new Vector2(-400, 1000));
    }
 }

} }

And here is for my object这是我的对象

private void OnTriggerEnter2D(Collider2D collision)
{
    if(collision.gameObject.tag == "Player")
   {
       _player.GetComponent<PlayerManager>().canSipa = true;
     }
}

 private void OnTriggerExit2D(Collider2D collision)
 {
    if (collision.gameObject.tag == "Player")
   {
   _player.GetComponent<PlayerManager>().canSipa = false ;
  }
 }

} }

add a second collider , slightly larger then the first, mark it trigger .添加第二个collider ,比第一个稍大,将其标记为trigger leave the smaller inner collider for physics.将较小的内部collider留给物理学。 you "foot" should enter the trigger and activiate it, then collide with the inner collider .你的“脚”应该进入trigger并激活它,然后与内部collider make sure the collider marked trigger is the larger one.确保对collider标记的trigger是较大的trigger

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM