In Unity3d, i can go the normal of the surface with which the collider collides using hit.normal, but is there a way to discover which side has been hitting what is provided bu Unity3d?

One solution is to see the orientation of the normal, and should piece of work well for static objects merely what about dynamic and moving objects whose orientation changes?

asked Sep 16, 2011 at fifteen:47

user avatar

0

3 Answers 3

                  role OnCollisionEnter(collision : Standoff) {     var relativePosition = transform.InverseTransformPoint(standoff.contacts);      if(relativePosition.10 > 0)      {         print("The object is to the right");     }      else      {         print("The object is to the left");     }      if(relativePosition.y > 0)      {         impress("The object is above.");     }      else      {         print("The object is below.");     }      if(relativePosition.z > 0)      {         impress("The object is in front.");     }      else      {         print("The object is behind.");     } }                                  

user avatar

derHugo

67.5k 9 gilded badges 52 silvery badges 92 statuary badges

answered Sep 16, 2011 at sixteen:xiii

user avatar

ane

                void OnCollisionEnter(Collision collision) {                 Vector3 dir = (collision.gameObject.transform.position - gameObject.transform.position).normalized;      if(Mathf.Abs(dir.z) < 0.05f)     {         if (dir.x > 0)         {             print ("RIGHT");             }         else if (dir.x < 0)         {             print ("LEFT");                      }     }     else     {         if(dir.z > 0)         {             print ("FRONT");         }         else if(dir.z < 0)         {             print ("BACK");         }     } }                              

user avatar

derHugo

67.5k 9 aureate badges 52 silver badges 92 statuary badges

answered May 24, 2015 at 0:36

user avatar

This works:

                office OnCollisionEnter(standoff: Collision) {     var relativePosition = transform.InverseTransformPoint(collision.transform.position);      if (relativePosition.x > 0)      {         print ("The object is to the correct");     }     else      {         print ("The object is to the left");     }      if (relativePosition.y > 0)      {         print ("The object is above.");     }      else      {         print ("The object is below.");     }      if (relativePosition.z > 0) {         print ("The object is in front.");     }     else      {         print ("The object is behind.");     } }                              

user avatar

derHugo

67.5k 9 gilt badges 52 silver badges 92 statuary badges

answered Mar 26, 2017 at 19:10

user avatar

Not the reply you lot're looking for? Browse other questions tagged collision-detection unity3d game-physics or ask your ain question.