- Home /
 
 
               Question by 
               Gnomemann · Jun 15, 2019 at 08:51 PM · 
                bulletnormals2d rotationtop down shooterimpact  
              
 
              How can I rotate an object towards a collision normal in 2D?
Hello, I would like some help with rotating my bullet impacts away from the wall in a top-down 2d game. I have managed to make it work somewhat but when I shoot a bullet at a top wall the impact rotates in the x-axis instead of the z-axis like all the other walls.
Here is my code, any help is appreciated.
 private void OnCollisionEnter2D(Collision2D other)
     {
         if (other.collider.CompareTag("Enemy"))
         {
             other.gameObject.GetComponent<Health>().TakeDamage(projectileDamage);
         }
         else
         {
             Vector2 pos = other.contacts[0].point;
             Quaternion rot = Quaternion.FromToRotation(Vector2.up, other.contacts[0].normal);
             Instantiate(impactPrefab, pos, rot);
         }
 
         gameObject.SetActive(false);
     }
 
              
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Bullet impact effect not working. Made from a Brackeys tutorial 2 Answers
how to rotate to face camera point in 2D 2 Answers
Calculating a bullet time of impact based on speed and distance 1 Answer
How to add impact sparks / blood effects to 2D shooter? 2 Answers
How to do bullet spread in 2D? 1 Answer