Hi there!
I’ve looked around a while for this, found that there was no solution in-Unity for this, and resorted to making my own implementation of it, but I would want to perhaps know the reason for lack of this.
In OnCollisionEnter, collision.relativeVelocity only returns the linear velocity of 2 rigidbodies, not factoring in the angular velocity at all. In a hypothetical example, having a spinning object hit a still object would result in 0 relative velocity as neither were linearly moving.
collision.impulse also results in strange behavior sometimes that is not acceptable for my usage, I’ve gotten instances of times where relativeVelocity reported as ~18 while impulse was 0.
I don’t expect relativeVelocity to factor in angular velocity as that would obviously result in a lot of previous projects breaking, but is there some kind of chance we could get some implementation of this with angular velocity factored in? Perhaps something along the lines of collision.pointVelocity.
For reference, this is how I implemented it for my stuff, disregarding the collision handling and just storing the last tick’s velocity.
Vector3 thisRBVel = lastTickState.velocity + Vector3.Cross(lastTickState.angularVelocity, point - lastTickState.position - Rigidbody.centerOfMass);
Vector3 otherRBVel = Vector3.zero;
if(otherBody != null) {
otherRBVel = otherBody.lastTickState.velocity + Vector3.Cross(otherBody.lastTickState.angularVelocity, point - otherBody.lastTickState.position - otherBody.Rigidbody.centerOfMass);
}
return otherRBVel - thisRBVel;
Maybe I totally missed some way to get this info, but this seems like it would be extremely useful for people to have in the collision report from OnCollisionEnter or Stay!
If anyone has any other solutions that the one I wrote, or perhaps if some Unity employee could chime in to give some insight, that’d be great