I am making a game where the player can place/build objects on the ground. There is a bug where if the player is clever enough they can place two or more objects inside of each other. The way I detect if the placement of an object is valid or not I use this script:
public class placementCheck : MonoBehaviour {
public static bool notInsideGround = true;
void OnTriggerEnter(Collider other)
{
notInside = false;
Debug.Log("enter!");
}
void OnTriggerExit(Collider other)
{
notInside = true;
Debug.Log("exit!");
}
}
As you can see it’s fairly simple. It’s exploitable by placing two objects close together and then with the third object slide it to the very edge of one of the objects so that the OnTriggerExit is called and you can place it since the OnTriggerEnter is only called right when you enter the object.
I have also tried using OnTriggerStay as well but with that, since it isn’t called every frame you can move your mouse quickly and at the right moment manage to get the object inside.