Search Unity

Explosion on collision at a certain velocity

Discussion in 'Physics' started by GameDevGary, Feb 8, 2015.

  1. GameDevGary

    GameDevGary

    Joined:
    Apr 15, 2014
    Posts:
    12
    Hi guys, I was just wondering how I could keep track of a rigidbody's velocity and check to see if it's hit anything.

    I think it would work somewhat like this in pseudocode.

    if(rigidbody.velocity >= someVelocity && (Some way to check collision))
    {
    DoExplosion();
    }

    Please forgive my ignorance on the topic. That's why I'm here though.

    I suppose the question is how do I check for collision against anything?

    Any help and/or input is greatly appreciated.
     
  2. Olipool

    Olipool

    Joined:
    Feb 8, 2015
    Posts:
    322
    GameDevGary likes this.
  3. GameDevGary

    GameDevGary

    Joined:
    Apr 15, 2014
    Posts:
    12

    I realized that I could just check the rigidbody's velocity in OnCollisionEnter() as soon as I posted the question, and created a simple working prototype in minutes. Haha. I've probably been using unity way too long to be asking these type of questions, I mainly ask them just to check myself, see if there's a better way of doing what I'm thinking about doing or doing, and to help spread knowledge to anyone who might have a similar question, but sometimes I'm just generally overthinking. Thank you for the help.
     
  4. Olipool

    Olipool

    Joined:
    Feb 8, 2015
    Posts:
    322
    I think its perfectly valid to ask just to check if there is a better way even if you got a working prototype :)
    Keep one thing in mind though, the velocity you are using may be correct but if you hit a target that is also moving fast, then it might be inapropriate to trigger the explosion because the impact is very small. Then the relativeVelocity ist better. But of course it depends on your game.
    Thanks for sharing your solution!