Instantiate at a right angle from collision impact

Hello, I’m trying to instantiate two prefabs at a right angle to the where the collider hits a target.

Background: I’m making my own version of Asteroids in Unity and when a laser hits a asteroid and the asteroid splits, I want it to split to either side of the impact point.

For example, a laser hits an asteroid:

--> O

I would instantiate a prefab above and below the asteroid because that’s at 90 degrees to the left and right of the laser’s impact point:

    x
--> O
    x

    public GameObject splitPrefab;

    void OnCollisionEnter2D(Collision2D coll)
    {
         Quaternion randomRotation;
         Vector3 newPosition;

         for (int i = 0; i < 2; i++)
         {
              // The position of the circle
              newPosition = gameObject.transform.position;

              // the Collision2D will give us information about the arrow
    		
              if (i == 0)
              {
                   // rotate left 90 degrees
              }
              else
              {
                   // rotate right 90 degrees
              }
    			
    
              Instantiate(splitPrefab, newPosition, Quaternion.identity);
          }
    }

I’m not sure what sort of math I need here to find the degree difference and then apply that to my newPosition with a distance for each prefab. The solution should work regardless of what direction the laser comes from; for example a laser could hit the same point on a asteroid but it could come directly towards the circle or be a glancing blow. I think in both situations it should be the same. The asteroid will likely be rotating and thus not stationary in that way.The distance between the asteroids center and the new prefab center would likely be a public variable that would depend on the game. This only needs to work in 2D.

There are two parts to your problem, figuring out what you want to use for the incoming vector, and finding the two perpendicular positions. The second half is the easy part. Given this code, I’m not sure what you want to use for the incoming vector. You might want to use the Collision2D.relativeVelocity. You maight want to use a vector between the center of the hitting object and the hit point. Reading between the lines for what you want to do, the hit.normal might be a good choice. Or maybe you save the pre-collision velocity of the projectile and use that. Assuming you have that and a you have the contact point from the collision, you can do:

 Quaternion q = Quaternion.AngleAxis(90.0f, Vector3.forward);
 Vector3 v = q * (incoming.normalized * dist);
 pos1 = contactPoint + v;
 pos2 = contactPoint - v;

An alternate solution to use a Quaternion to rotate the vector, would be to use Vector3.Cross();

 Vector3 v = Vector3.Cross(incoming, Vector3.forward);
 v.Normalize() * dist;
 pos1 = contactPoint + v;
 pos2 = contactPoint - v;

‘dist’ is the distance away along the perpendicular you want to place the point.