GearGuyCtrl1.OnCollisionEnter C# (CSharp) Method

OnCollisionEnter() public method

public OnCollisionEnter ( Collision coll ) : void
coll Collision
return void
    void OnCollisionEnter(Collision coll)
    {
        collidingWith[numCollidingWith++] = coll;
        if (coll.gameObject.transform==transform.parent)
            return;

        Rigidbody other = coll.gameObject.GetComponent<Rigidbody>();
        EnviroGear gear = coll.gameObject.GetComponent<EnviroGear>();
        if (gear!=null && gear.isMovable)
        {
            // average out velocities
            //print("this.vel: "+rigidBody.velocity+"; other.vel: "+other.velocity+"; impulse: "+coll.impulse);
            Vector3 totalVel = other.mass*other.velocity+rigidBody.mass*rigidBody.velocity-rigidBody.mass*coll.impulse;
            float totalMass = other.mass+rigidBody.mass;
            Vector3 finalVel = totalVel/totalMass;
            //print("finalVel: "+finalVel);
            other.velocity = 2*finalVel;
            rigidBody.velocity = 2*finalVel;
        }
    }