# Collision surface check.

 0 I want to check the surface in collision.for example, cube has six surface. so, I want to know when cube has collision which surface of cube has collision. more ▼ asked May 06 '12 at 05:26 AM Rikimaru 28 ● 5 ● 7 ● 13 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 You could use the normal of the hit and transform that to local space. To make things easier to compare just round the returning Vector3 and then compare the output. The code below should be enough to get you started on an implementation, although it's just tested in a very strict environment with a cube. Hope it helps! ``````#pragma strict function OnCollisionEnter (collision : Collision) { var contact : ContactPoint = collision.contacts[0]; var normal : Vector3 = contact.normal; var inverseNormal : Vector3 = transform.InverseTransformDirection(normal); var roundNormal : Vector3 = RoundVector3(inverseNormal); ReturnSide(roundNormal); } function RoundVector3 (convertThis : Vector3 ) : Vector3 { var x : int = Mathf.Round(convertThis.x); var y : int = Mathf.Round(convertThis.y); var z : int = Mathf.Round(convertThis.z); var returnVector : Vector3 = Vector3(x,y,z); return returnVector; } function ReturnSide (side : Vector3) { var output : String; switch (side) { case Vector3.down: output = "Down"; break; case Vector3.up: output = "Up"; break; case Vector3.back: output = "Back"; break; case Vector3.forward: output = "Front"; break; case Vector3.left: output = "Left"; break; case Vector3.right: output = "Right"; break; } Debug.Log(output+" was hit."); } `````` more ▼ answered May 06 '12 at 10:26 AM save 8.2k ● 22 ● 31 ● 62 thanks. I'll try it. May 06 '12 at 12:43 PM Rikimaru add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 Im pretty sure thats not possible. One way you could do it is create 6 plane colliders that side faced over each side of the cube. So each individual plane would offer different responses each cube face. more ▼ answered May 06 '12 at 05:33 AM GC1983 540 ● 18 ● 33 ● 44 I'm sorry for your answer. T.T There being no answer, I try to find another. anyway thanks~~~ May 06 '12 at 08:15 AM Rikimaru add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email: