x


Collision surface check.

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 gravatar image

Rikimaru
28 5 7 13

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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 gravatar image

save
8.2k 22 31 62

thanks. I'll try it.

May 06 '12 at 12:43 PM Rikimaru
(comments are locked)
10|3000 characters needed characters left

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 gravatar image

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
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2485
x59

asked: May 06 '12 at 05:26 AM

Seen: 524 times

Last Updated: May 06 '12 at 12:43 PM