G
G
GreatRash2013-12-18 11:09:06
Unity
GreatRash, 2013-12-18 11:09:06

Is it possible to resolve collisions in a loop instead of every frame?

The OnCollisionStay method runs every frame, and I need to run it inside Start. Can it be done?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Antipov, 2013-12-26
@AlieNCrazY

Coroutine
docs.unity3d.com/Documentation/Manual/Coroutines.html
d.pr/i/1cJW
This can be used as a way to spread an effect over a period time but it is also a useful optimization. Many tasks in a game need to be carried out periodically and the most obvious way to do this is to include them in the Update function. However, this function will typically be called many times per second. When a task doesn't need to be repeated quite so frequently, you can put it in a coroutine to get an update regularly but not every single frame. An example of this might be an alarm that warns the player if an enemy is nearby.
OnCollisionStay can be a co-routine, simply use the yield statement in the function.
docs.unity3d.com/Documentation/ScriptReference/Mon...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question