Hi,
I’m trying to detect collisions between a collider and other objects, and then apply a reaction impulse that rapidly pushes the object away from the collision point. To do this, I take the first contact normal found in OnCollisionEnter() and apply a relatively large force (in my world, 1 unit = 1 m and the object is small, so 0.75 is a large magnitude) in the direction of the normal. Code below.
private void OnCollisionEnter(Collision collision)
{
Vector3 normal = collision.contacts[0].normal;
m_rb.AddForce(normal * 0.75f, ForceMode.VelocityChange);
// Debug: draw normal
LineRenderer lr = GetComponent<LineRenderer>();
lr.positionCount = 2;
lr.SetPosition(0, collision.contacts[0].point);
lr.SetPosition(1, collision.contacts[0].point + normal);
lr.useWorldSpace = true;
}
The problem is that the reaction is totally inconsistent. Sometimes, it appears as though a large magnitude velocity change occurs, and other times, the effect is tiny.
Here’s a video of the problem.
Note how it sometimes gets pushed strongly but other times less so, especially when colliding horizontally against the wall (the black region it collides with has an invisible mesh – sorry for the confusion). It has nothing to do with the applied forces used to steer the helicopter (because if anything, the faster it moves toward the ground, the larger the bounce, despite the reaction being opposite to the control inputs). I’m printing out collision.impulse and it’s always zero. What’s going on here and how can I achieve a more consistent effect?
Thanks!
Bart