KROYSDOCS
HomeWhat's newv0.1.0
SCRIPTING API / Scripts and entities / WaitForFixedUpdate

WaitForFixedUpdate

Continues the coroutine in the next fixed step, after this script's OnFixedUpdate. Use it for physics changes; a loop around it runs once per step.

Kindclass
NamespaceKroys.EngineScripting
Members0
SourceCoroutine.cs
EXAMPLE

In a script

A complete script that uses WaitForFixedUpdate; copy it into your scripts project.

Coroutines.cs
public sealed class LaunchPad : EntityScript
{
    public int PushSteps = 10;
    public float SpeedPerStep = 1.5f;

    protected override void OnTriggerEnter(Entity other) => StartCoroutine(Push(other));

    private IEnumerator Push(Entity body)
    {
        // Physics changes belong in the fixed step: resume once per step, PushSteps times.
        for (int step = 0; step < PushSteps; ++step)
        {
            yield return new WaitForFixedUpdate();
            if (!RigidBody.Has(body)) yield break;
            Vector3 velocity = RigidBody.GetLinearVelocity(body);
            velocity.Y += SpeedPerStep;
            RigidBody.SetLinearVelocity(body, velocity);
            RigidBody.SetAwake(body, true);
        }
    }
}

KroysEngine 0.1.0 documentation, built from the engine repository by Tools/BuildDocsSite.py.