- Home /
No good answer, found a solution
How do I check for triangle triangle intersection?
I found this old code: http://fileadmin.cs.lth.se/cs/Personal/Tomas_Akenine-Moller/code/opttritri.txt But I need a version for unity because I can't use physics. Is there a solution for this because converting this takes time.
Are your triangles in a 2D or 3D environment ? If they are coplanar, the test will be a lot easier. It is also possible in 3D but it will be more complicated.
Answer by wesleywh · Dec 19, 2014 at 06:02 PM
You could use the built in function called:
OnCollisionEnter(), OnCollisionExit(), or OnCollisionStay().
Each does something different but the names should be straight forward. These require you to have a collider attached to both objects. Here is some Example code of how you could use this:
//JavaScript - Collider
OnCollisionEnter(other : Collision)
{
if(other.tag == "Player")//if there person hit is tagged player show this message in the log.
{
Debug.Log("Player Hit!");
}
}
//C# - Collider
OnCollisionEnter(Collision other)
{
if(other.tag == "Player")//if there person hit is tagged player show this message in the log.
{
Debug.Log("Player Hit!");
}
}
You could also use:
OnTriggerEnter(), OnTriggerExit(), OnTriggerStay().
This just checks if your object is inside a specifc area. This also requires a collider component attached to only 1 of the objects. It also needs to have the "isTrigger" tick box checked. Here is an example of how you could use this:
//Javascript - Trigger
OnTriggerEnter(other : Collider)
{
if(other.gameObject.tag == "Player")//checks if there person entering is tagged "player"
{
Debug.Log("Player Entered!");
}
}
//C# - Trigger
OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "Player")//checks if there person entering is tagged "player"
{
Debug.Log("Player Entered!");
}
}
I can't use physics. They cannot be used multiple times in one frame.