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

Force Applied to Rigidbody

Discussion in 'Editor & General Support' started by miqvp22, Jan 17, 2019.

  1. miqvp22

    miqvp22

    Joined:
    Jan 17, 2019
    Posts:
    9
    I want to know how much damage is taken by a Rigidbody on impact, to do so It is a common practice to use RELATIVEVELOCITY OnCollisionEnter.

    But what if I have the following example (attatched image file).
    Rigidbodies A and B should take more damage than C, and I can't use relative velocity because is 0.

    I would like to find a very flexible solution (i.e. not an upwards raycast to sum mass) to know how much damage is receiving every object on impact.

    question.jpg
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    First, there's a forum just for physics in Unity, so you should use that forum for these kinds of questions in the future.

    You should at the 'impulse' property of the collision. It represents how much force is actually generated by the collision, taking into account the mass of objects, and the actual simulation.

    Note that OnCollisionEnter likely won't work on its own for your purposes, because you'll miss any forces being applied to objects that are already touching. In your example, if the sphere struck the red block, you probably wouldn't get an OnCollisionEnter event involving block "A", because block "A" was already touching the red block. So you'll probably want to also be handling OnCollisionStay, which will give you additional force applied to a stack of objects that were already touching.
     
  3. miqvp22

    miqvp22

    Joined:
    Jan 17, 2019
    Posts:
    9
    Collision2D doesn't have Impulse property
     
  4. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    Okay. Well, you said OnCollisionEnter earlier, not OnCollisionEnter2D...

    2D physics is a completely different API in Unity, and not as full-features (it seems) as 3D/PhysX physics. I don't know how to achieve what you're trying to do in 2D. It might seem like a lame solution, but an approach you could take is to build your game/project in 3D with some position constraints added to the rigidbodies, along with the camera constraints to make it look more 2D, if you need an improved physics simulation. Or see if the asset store has some 2D physics replacement.
     
  5. miqvp22

    miqvp22

    Joined:
    Jan 17, 2019
    Posts:
    9
    Thank you for the quick answer. But I cant contemplate to change my game in fake-2D at this point.
    Hope that there exists a solution for that simple problem in 2D.