Simulating fixed time step inside coroutines

Since coroutines run at a variable frame rate, how would you move a physics object inside a coroutine?

variable time delta? maybe, but on the iphone frame rates can have huge deltas

I’m trying to move the objects with a simulated time step; so far, working ok. Let me know your thoughts, maybe there is a better way.

using UnityEngine;
using System.Collections;

public class SimFixedTime : MonoBehaviour {
	
	void Start () {
		StartCoroutine(Simulate());
	}
	
	IEnumerator Simulate () {
		
		bool done = false;
		float accumulator = 0;
		int fpsFixedSimulated = 0;
		float frameTime = 0;
		
		while (!done) {
			
			accumulator += Time.deltaTime;
			if (accumulator > Time.fixedDeltaTime) {
				accumulator -= Time.fixedDeltaTime;
				++fpsFixedSimulated;
				// move physics here
			}
			
			// optional, for debug
			frameTime += Time.deltaTime;
			if (frameTime > 1) {
				Debug.Log("Simulated fixed fps: " + fpsFixedSimulated.ToString());
				frameTime -= 1;
				fpsFixedSimulated = 0;
			}
			// end optional
			
			yield return 0;
		}
	}
}

Bump this, is it possible to wait for a different deltaTime as fixed time step?

you would use yield return new WaitForFixedUpdate() wouldn’t you?

all these fake replicas are not bound to the physics update point in time and still backfire ugly. it gets you a fixed rate yeah but no physics update rate.

Probably best to just have the object in question have it’s own script (you can use the same script for all of this). Then the co routine can modify variables, and fixed update on the object’s personal script can execute this.