Apply force in non-update function?
Hi,
I have a general question about where to apply force/manipulate physics. I have a gameobject which controls spawning of a sphere by institating the object and applying force afterwards. It spawns only one sphere as long as the sphere does not leave the boundaries of the level. I currently do this in a function "SpawnObject" which is called by other GameObjects in the scenes, but the institating and applying force does not happen in an Update function (i.e. not in Update or FixedUpdate):
void SpawnObject(){
//instantiate object and apply force
}
I observed now, that the physics behavior depends on the computer I use and I guess this is because I don't manipulate the physics in FixedUpdate.
But how should I handle this? Can I fix the SpawnObject function that it works device independent? My other idea is to apply force in FixedUpdate, but than I have to use a boolean to control that only one object spawns the time:
void FixedUpdate(){
if (spawn){
// spawn object, apply force
spawn = false;
}
}
public void SpawnObject(){
spawn = true;
}
But this solution looks ugly to me, because Unity will have to check the if statement every frame. What is the best solution to solve this?
Thanks in advance!!