Rigidbody magnitude comparison is not working correctlly?

i want to compare the magnitudes of two rigidbodies and destroy the one that is moving slower when they collide. I do this by comparing the magnitudes of the 2 rigidbodies. It works fine most of the time but sometimes the wrong object gets destroyed, and when this happens one of the objects is completely at rest and the other is moving, so there is no way that the magnitudes would be equal. The code looks likes this:

function OnCollisionEnter(collision : Collision) {

	

	if(collision.gameObject.tag == "projectile") {
	
	
		if(collision.rigidbody.velocity.magnitude < rigidbody.velocity.magnitude)     {
			
			  collision.gameObject.GetComponent(ProjectileScript).destroyMe(player);
			
		}
		
		
		
	}

any ideas??

The magnitude inside OnCollisionXXX is the magnitude after the collision has been processed by the physics engine.

If you want the magnitude before the collision, you will have to save it in a variable and update it each FixedUpdate (in both scripts):

var prevSqrMagnitude : float;

void FixedUpdate()
{
    prevSqrMagnitude = rigidbody.velocity.sqrMagnitude;
}

Then, in the script with the OnCollisionEnter function:

function OnCollisionEnter(collision : Collision) {
    if(collision.gameObject.tag == "projectile") {

        var projectile : ProjectileScript = collision.gameObject.GetComponent(ProjectileScript);
        if(projectile.prevSqrMagnitude < prevSqrMagnitude ) {
            projectile.destroyMe(player);
        }
    }
}

@Lo0NuhtiK may be right: the velocities may have been changed by the collision. You could store the velocities in FixedUpdate in both objects and compare them:

var lastVel: float = 0;

function FixedUpdate(){ // this function must exist in both scripts!
  lastVel = rigidbody.velocity.magnitude;
}

function OnCollisionEnter(collision : Collision) {
    if (collision.gameObject.tag == "projectile") {
        var otherScript = collision.gameObject.GetComponent(ProjectileScript);
        if (otherScript.lastVel < lastVel){ // compare the velocities prior collision
            otherScript.destroyMe(player);
        }
    }
}