Is it okay to use the AddForce function in the OnTriggerEnter function or is it better to use a flag instead, that will activate AddForce in the FixedUpdate() function??
asked Aug 20 '12 at 02:34 AM
It's absolutely fine to use it in OnTriggerEnter since it's a one-time-event. Keep in mind that you might want to use a different ForceMode, usually Impulse or VelocityChange.
If you want to apply a force over time, it should be done in FixedUpdate.
An very easy solution is to use a booster script which you attach to your object when it should be boosted. This component would remove itself after the boost is over. It's also possible to use a prefab which contains a boost script that you would attach as child to the boosted object. This as the additional advantage that you can add particle / sound effects to the prefab and you get the effects for free.
Here's the component solution
I guess you use UnityScript?
On your "boosting device" script
This will add a "booster" component to every rigidbody that enters the trigger. It will set the boost direction / force and how long it should be boosted.
The component will destroy itself after the boosting time. As long as it's attached it will apply a constant force to the RB which will accelerate it continuously. Keep in mind that you have to configure the boosting time and the force in the inspector to match your desired acceleration.