Search Unity

Reuse bullet with rigidbody collision (not using Trigger)?

Discussion in 'Physics' started by VipHaLongPro, Apr 25, 2015.

  1. VipHaLongPro

    VipHaLongPro

    Joined:
    Mar 8, 2015
    Posts:
    49
    My bullet is just a simple capsule object. It should aim (its forward axis) directly to the target. When using trigger, everything works OK. But when I tried using collision (disable isTrigger), the bullet works only the first time shot out from the barrel. The next times, its forward axis seems to be rotated over time, although it still moves toward the target.

    Of course if destroying the bullet and instantiate a new one, there won't be any issue. But the bullet is reused. I think the problem could be after colliding with the target the first time, the rigidbody effect is still applied the next time the bullet starts from the barrel causing the rotation over time.

    I does have a simple fix with this issue by setting freezeRotation to true (or tick all 3 X,Y,Z in the Freeze Rotation constraint of the bullet shown in Inspector window). However I would like to understand how we can stop all the rigidbody effect caused by the previous collisions and continue using it from start? In other words, I believe there should be another solution for this issue.

    I hope someone here has experienced and understood why and how to fix it in another way (other than setting freezeRotation to true). Thanks!
     
  2. andrew-lukasik

    andrew-lukasik

    Joined:
    Jan 31, 2013
    Posts:
    249
    It's caused by angularVelocity received from collision. Just reset it to Vector3.zero or to transform.forward (spin) OnEnable().
     
    VipHaLongPro likes this.
  3. VipHaLongPro

    VipHaLongPro

    Joined:
    Mar 8, 2015
    Posts:
    49
    Wow great. That's it. Thank you very much :)