Search Unity

Question Ignore physics between 2 objects, but do not ignore their collision

Discussion in 'Physics' started by hamik166, Aug 27, 2020.

  1. hamik166

    hamik166

    Joined:
    Oct 19, 2019
    Posts:
    31
    I have 2 gameobject, one is a spinning stick, and another one is a bullet.

    the bullet has collider 2D, and the stick has collider 2D and rigidBody 2D

    the spinning stick should spin when a bullet hits it.
    I want to carefully choose the amout of spin with AddTorque(x). when I detect a colision with OnCollisionEnter2D()

    the problem is that when a bullet hits the stick. the physics does its thing, and it moves/spins it. but I don't want it to happen because I want to do it by myself with code to get the exact amount of spin.

    I cannot use the collision matrix because if I disable the collision between them, then I cannot use OnCollisionEnter2D().

    So how do I detect the collision between them without moving the stick?
     
    ChiliStudio likes this.
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,428
    Use a Kinematic Rigidbody2D then set the angular velocity upon collision. Kinematic bodies won't respond to forces you add or gravity or collision detection forces.

    If you're using a Dynamic body then dynamically responding to forces is what it does so you can't just turn it off otherwise this would not be a Dynamic body.