Using InvokeRepeating()
Hi,
I'm new to Unity so I'm sorry if this question is too basic or been asked before. I'm trying to export position and rotational acceleration of a player controlled sphere. To do this I've made two simple functions, both in one script, where one adds position to a List and the other rotational acceleration to another List.
void RecPoint()
{
positions.Add(transform.position); // store current position...
}
void RecAngVel()
{
angVels.Add(rb.angularVelocity); // store current angular velocity...
}
To come up with a bunch of values I call InvokeRepeating() in the Start function twice. The first time I give InvokeRepeating() my RecPosition() function as input and in the second call I give it RecAngVel() as input. I've then got a GUI button set up that, when pressed, cancels the two calls to InvokeRepeating() and exports the data to a text file.
void Start () {
positions = new List<Vector3>();
angVels = new List<Vector3>();
rb = GetComponent<Rigidbody>();
// tSample = time after which to first call specified function
// interval = how frequently the function should be called after initial call
InvokeRepeating("RecPoint", tSample, interval);
InvokeRepeating("RecAngVels", tSample, interval);
}
My issue is that I don't get an equal amount of data points for position and angular velocity but rather I get more position data than angular velocity data and I'm not sure why. Based on the code above I would assume that an equal amount of data would be stored into each list, but that's not the case. Is it because I call InvokeRepeating() with RecPosition() before RecAngVel()? Or is it something else that I'm missing?
I've been trying to figure this out for a few days now and I'm not making any progress, so I honestly appreciate any help or advice that people can share. Thanks in advance!
88 for position and 22 for angular velocity, so they differ by 66. In the above code, I set tSample = 0.f and interval = 0.1f if that makes a difference.
ok, the way they're called is exactly the same. I don't think this code is the problem. but I said that in your other post :)
Your answer
![](https://koobas.hobune.stream/wayback/20220612112424im_/https://answers.unity.com/themes/thub/images/avi.jpg)