'Check for trigger entry point in axis
I have two gameObjects which are having triggers. I am able to detect if a gameObject is coming in contact with another using OnTriggerEnter(). Now I would like to know from which axis it has been entered. I just want to detect the point of entry for the collision. How do I achieve this?
public int error_x = 0;
void Start () { }
private void OnTriggerEnter (Collider col) {
if (!enabled) return;
if (col.gameObject.name == "Cube01") {
error_x++; //only if the entry point is in x axis
}
}
private void OnTriggerExit (Collider col) {
if (!enabled) return;
if (col.gameObject.name == "Cube01" ) {
}
}
Solution 1:[1]
You can simply check if the x position of your collider is greater than the triggers x position:
if(col.transform.position.x > transform.position.x){
//The collider touched from the x axis
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | zenonet |
