I’m wanting to check the position of an object x times every second, and add those positions to an array. I believe the formula I have is correct, but I’m getting inconsistent and sometimes inaccurate results. I’m obviously missing something. Any help is appreciated.
var posArray = Array(Vector3);
var nextActionTime : float = 0.00;
var sampleRate : float = 20; //check twenty times per second
function Update () {
if (Time.time > nextActionTime) {
nextActionTime = Time.time + (1/sampleRate);
GetPosition();
}
}
function GetPosition () {
posArray.Add(gameObject.transform.position);
}
This should be adding a value to the posArray 20 times per second (or, once every 0.05 seconds), but like I stated above it’s inconsistent. Would this “sample rate” be affected by frame rate? Is my math/logic flawed?