I’m hitting a wall and trying to get a little more realistic movement in the hit areas. I don’t want the entire wall to be effected, just the hit pieces. So my wall is made from mesh colliders set to kinematic. When hit, they are destroyed, smoke and parts brought in and pushed as if they themselves were hit. And there’s my problem, how to apply the impact force to the new pieces. Here’s what I have on the wall pieces:
var Toughness = 15;
var wear_n_tear = 0;
var wall_smoke:Transform;
var tmp_wall:Transform;
function OnCollisionEnter(collision : Collision) {
var collider : Collider;
wear_n_tear += collision.relativeVelocity.magnitude;
if (wear_n_tear > Toughness){
Destroy (gameObject);
var wallSmoke = Instantiate(wall_smoke, transform.position, Quaternion.identity);
var blast_peice1 = Instantiate(tmp_wall, transform.position, Quaternion.identity);
this.rigidbody.AddExplosionForce(collision.relativeVelocity.magnitude, transform.position, 5, 3.0);
}
}
this is okay but the new peices just fall straight down, not like they were just hit and broken up.
I’d like to be able to get the point of contact from the bullet(clone) and the wall peice, and use that with the magnitude to push a couple new peices around.
Maybe I’m going about this all wrong? Thanks for any guidance! 
Hi, welcome to the forum!
You’ll notice the Collision object passed to the OnCollisionEnter function has an array called contacts which is a list of the contact points between the colliders. When the bullet strikes, you can use the position from the contact point and the direction of the bullet’s travel as parameters to rigidbody.AddForceAtPosition. Instead of pushing the pieces at their centre of mass, this function will apply a force at the chosen position and will also add torque as a result.
function OnCollisionEnter(coll: Collision) {
var pos = coll.contacts[0].point;
coll.rigidbody.AddForceAtPosition(pos, transform.forward * bulletForce);
}
I must be doing something wrong, this script has no effect on the motion of the two spheres I have colliding. Sphere1 is given a push
var bulletForce = 100;
function Awake(){
rigidbody.AddForce(transform.forward * bulletForce);
}
function OnCollisionEnter(coll: Collision) {
print("sphere1: magnitude = " + coll.relativeVelocity.magnitude + " at " + coll.contacts[0].point);
}
and sphere2 has this script.
var test_sphere:Transform;
/*function OnCollisionEnter(coll: Collision) {
var pos = coll.contacts[0].point;
print("sphere2 hit: coll.relativeVelocity.magnitude = " + coll.relativeVelocity.magnitude + " at point: " + pos);
var test_sphere = Instantiate(test_sphere, transform.position, Quaternion.identity);
test_sphere.rigidbody.AddForceAtPosition(pos, transform.forward * 999999999999999999);
Destroy (gameObject);
}*/
function OnCollisionEnter(coll: Collision) {
var pos = coll.contacts[0].point;
print("sphere2 hit: magnitude = " + coll.relativeVelocity.magnitude + " at point: " + pos);
coll.rigidbody.AddForceAtPosition(pos, transform.forward * 999999999999);
}
on sphere2, turning the script on or off doesn’t change anything. It reacts normally to being bumped by the other rigid body with a sphere collider.
print output:
sphere2 hit: magnitude = 0 at point: (1.0, 3.7, 0.0)
sphere1: magnitude = 4.019202 at (0.6, 3.7, 0.0)
sphere1: magnitude = 3.570836 at (0.8, 3.7, 0.0)
sphere1: magnitude = 3.570763 at (0.9, 3.9, 0.0)
sphere2 hit: magnitude = 3.570763 at point: (0.9, 3.9, 0.0)