How to get a cube to scale on the side of a collision

Sorry if this is in the wrong forum, as I’m new to unity and even newer to the forums.

I am trying to have a cube “grow” in the direction of the side that is hit by a “bullet” (I.E. if it is hit on the left side, it would scale in that direction). I am trying to do this using Rigidbodys, and OnCollisionEnter, and using the normal of the Collision to get the scaling direction. This works when the cube is stationary, however when it starts to rotate, the “normal” ends up scaling it in multiple directions. Now I’m pretty sure this is due to the normal using World Coordinates and not accounting for the cubes rotation, however for the life of me, I can’t figure out how to get Collision.contacts[0].normal to account for the cube’s rotation.

Here’s the code I am using.

The Bullet’s code:

void OnCollisionEnter(Collision collider)
    {
        if (collider.gameObject.tag == "enemy")
        {
            var objectHit = collider.gameObject;
            var hitHandler = objectHit.GetComponent<bulletHit>();
            hitHandler.growOnHit(-1 * collider.contacts[0].normal);
            Debug.Log("passed normal");
        }
       
    }

and the cube’s (relevant) code:

public void growOnHit(Vector3 growthDirection)
    {
        m_Transform.localScale +=growthDirection * growthScale;
    }

I believe you’re looking for:

collider.transform.InverseTransformDirection(-1 * collider.contacts[0].normal)

This transforms a worldspace direction vector into the transform’s local space.

https://docs.unity3d.com/ScriptReference/Transform.InverseTransformDirection.html

Thanks! That ended up working for me. I had tried that before but I guess I wasn’t too sure how to use it and so I had it in the wrong spot. It does still seem to affect multiple dimensions anyway, but it is only changing by .000xx. Is that just a consequence of using floats or the math involved for the conversion?

A little of both, basically.