I got a quesion. In my “game” I would like to know if there is free space above the objects.
For this purpose I use BoxCollider. I move BoxCollider above the objects.
OnTriggerEnter function tells me is there anything in the BoxCollider space.
Here is a simplified code :
before the program checks the trigger. It uses yield WaitForSeconds(0.5) and without it there is no chance to make it work properly. And this is my question -
if I can somehow set the optimum value of WaitForSeconds() function (in this case the value of (0.5))? Now script works fine but I’m afraid that if the script will be part of the game this value 0.5 seconds may be too small. I have no idea where it depends I know that I can
guess, but it’s not a good way of programming
Do not you look at the accuracy of the code because it is only an example
//variable which changes by the trigger
var crash : boolean = false;
// invisible object with BoxCollider appears 4 meters above the 1st target
Transform.position = Vector3(someobject.x,someobject.y + 4,someobject.z);
//temporarily stop the script to OnTriggerEnter() function could change the value of the variable "crash" before being read
//If I remove this line of code value "Crash" will always be false.
//OnTriggerEnter function does not have time to change it
yield WaitForSeconds(0.5);
// if the value "crash" is changed to "true" by OnTriggerEnter() functions means that within the collider is some other object ,if so then finish the action
if (crash)
{
print("not empty space");
return;
}
// then the same invisible object appears 4 meters above the 2nd target
Transform.position = Vector3(other_object.x,other_object.y + 4,other_object.z);
........ // then code is repeated
function OnTriggerEnter(col : Collider ) {
if (col.gameObject.name != "FlyBot")
{
crash = true;
}
Generally, in real script there is no Update function
Maybe I do not understand something but I do not see any reason to use Update function or IEnumerator
My question is in fact simple : Is it possible to predict how long time OnTriggerEnter function needs to to update one varaiable ?
I think your problem lays with colliders not actually moving and triggering until the next physics update. If you have specific objects you want to check, you might achieve the desired result with methods on the Bounds of the other objects’ colliders: