- Home /
Face detection
What is the best way to detect the faces of a cube, and then store these? So an object works out if each face is being touched.
I've considered doing multiple raycasts, but that probably won't be great for performance. I also considered doing an OverlapSphere on every face, but that could get confusing in the hierachy with lots of objects? Also, they are quite expensive. So how would you do it?
Whew. I thought you wanted to see where a person's face was in a webcamera!
What do you mean by "being touched"? Do you mean that other objects touches all sides at once of that cube? Or do you mean that you have to touch one by one and you want to detect when all have been touched?
I mean detect others objects, which are touching the cube for the other time.
Answer by Chris D · Jun 17, 2011 at 07:48 PM
Well, using OnCollision(), you can use the Collision info it supplies to return the triangles currently being touched. As long as you keep an index of which triangles are on each face (generally 2, I think?), you should be able to tell which faces are currently being collided with.
I'm not sure that's less expensive than raycasting, however. It might be worth it to try both ways.
Could you give a code example? There's nothing in the docs about triangles.
Something else I could try would be to mark the collision points, and work out where they are using a distance command? Any thoughts on this?
Ya...I think it comes down to procedurally editing your $$anonymous$$esh uvs: http://unity3d.com/support/documentation/ScriptReference/$$anonymous$$esh.html
Unfortunately, I don't know enough about this stuff to be much more help, sorry :(
Your answer
Follow this Question
Related Questions
Rotate cube according to position of another object? 1 Answer
How to make a dragable cube? (iphone) 1 Answer
Random place changement 2 Answers
Mesh cuboid sides not straight 1 Answer
How can I see a Cube ? 0 Answers