Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bullet ricochet - minimal angle

Discussion in 'Physics' started by Ether141, Oct 13, 2019.

  1. Ether141

    Ether141

    Joined:
    Jul 30, 2018
    Posts:
    21
    I create realistic bullet physics based only on raycasts. Now I make bullet ricochet. Ricochet works well, but I'd like to limit the angle at which the projectile will bounce. At the moment of bullet hit I get hit direction and ricochet direction. How can I limit this if eg. hit angle is less than 20 degress bullet will bounce, otherwise won't.


    Direction = (0.2, 0, 1.0)


    Direction = (0.9, 0, 0.3)
     
  2. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    927
    Simply use the Vector3.AngleBetween() Function to check and limit the angle;)
     
    Ether141 likes this.
  3. Ether141

    Ether141

    Joined:
    Jul 30, 2018
    Posts:
    21
    I used Vector3.Angle instead of Vector3.AngleBetween ('cause AngleBetween is obsolete) and it works great. Thank you so much bro :D .