How To Register If A Mob Has Been Hit
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
SpeedBirdNineSpeedBirdNine
four,530 xi golden badges 45 silver badges 65 bronze badges
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."); } }
derHugo
67.5k 9 gilded badges 52 silvery badges 92 statuary badges
answered Sep 16, 2011 at sixteen:xiii
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"); } } }
derHugo
67.5k 9 aureate badges 52 silver badges 92 statuary badges
answered May 24, 2015 at 0:36
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."); } }
derHugo
67.5k 9 gilt badges 52 silver badges 92 statuary badges
answered Mar 26, 2017 at 19:10
Adam StaszakAdam Staszak
ane,094 eleven silverish badges xv bronze badges
Not the reply you lot're looking for? Browse other questions tagged collision-detection unity3d game-physics or ask your ain question.
How To Register If A Mob Has Been Hit,
Source: https://stackoverflow.com/questions/7447271/how-to-find-which-side-of-a-collider-has-been-hit-from-hit-normal
Posted by: jenningsramord94.blogspot.com

0 Response to "How To Register If A Mob Has Been Hit"
Post a Comment