Search code examples
unity-game-enginegame-physics

Acess normal force/impulse between rigid bodies


I'm making a catapult game in Unity 3d. When the stones from my catapult hit the walls of enemy castles, or when a tower of an enemy castle crumbles together, I will need the force between rigid bodies, to calculate damage. Relative velocity is not enough, as it does not take into account the mass. Multiplying the relative velocity and the masses will not help either, since I would need to know the possition of the contact points relative to the bodies center of masses, and their rotational inertia. The stone might hit a wall directly, or beeing reflected. This impulse value must exist somewhere in the physics enginse, since it is used in the physics engine, but I cannot find it anywhere.

Example code of what I want:

void OnCollisionEnter(Collider other){
    float force = other.relativeForce;
    if (force > breakLimit){
        Destroy(gameObject);
        Instantiate(Debri, transform.position, transform.rotation);
    }
}

Solution

  • You might need to know some physics equation or principle: i.e. 1/2 mv^2 the Kinetic energy of your stone.

    To make it simple:

    <Kinetic energy before collision> = <Kinetic energy after collision> + energy accepted by the wall.
    

    Hope it would help u.