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;
}