Hi,
I’m a little confused about InvokeRepeating(). I’m mainly using multiple calls to InvokeRepeating() in Start() to repeatedly call some of my own functions that record the current position and angular velocity of a player controlled object as well as the current time.
void Start () {
positions = new List<Vector3>(); // initialize array...
// and start recording after tSamples
angVels = new List<Vector3>();
com = new List<Vector3>();
time = new List<float>();
rb = GetComponent<Rigidbody>();
com.Add(transform.TransformPoint(rb.centerOfMass)); // Converts COM coors to global instead of local,
// is this what you want?
InvokeRepeating("RecPoint", tSample, interval);
InvokeRepeating("RecAngVels", tSample, interval);
InvokeRepeating("RecTime", tSample, interval);
}
So since I want to start recording data as soon as the game starts I set tSample = 0.0f and I set interval = 0.1f so that I would grab data every tenth of a second, or get 10 data points every second. Is this approach logically sound or am I misunderstanding something about InvokeRepeating(), particularly about the start time parameter?
I’ve got a GUI button set up that calls CancelInvoke() once for each of the calls to InvokeRepeating() and transfers the stored data into different text files. My issue is that when tSample = 0.0f and I hit the button to stop recording values within 10 seconds I get no data stored at all. If I let the game run for 10+ seconds I’ll start to store data just as I would expect. But I really need to start grabbing that data at the start or as close as I can get to it.
With my current set up, if I wait 3 seconds before hitting that button I would expect to get 30 data points for each quantity, but right now I’m getting nothing. If I wait 11.47 seconds I get 22 data points instead of the expected ~114 data points. Am I thinking about how InvokeRepeating() works correctly? Is my expectation with this setup even correct?
I suppose I could set tSample=10.0f and not give any inputs until 10 seconds have passed to essentially make it seem like the recording started at 0 seconds, but I really don’t like this approach as it seems like a cop out and a non programmatic solution to my problem.
I’m really open to any advice you guys may have and I really could use some help with this as this and some other issues have really stopped me in my tracks. Thanks in advance!