- Home /
Movement by increment jerkiness
G'day guys,
I'm building a maze-collection game, and using a multidimensional array for movement (that's what [rowIndex] and [colIndex] deal with). My issue is a slight 'jerk' at each new 'grid'. I understand, from looking at a similar system that was put up on the scripts wiki ( http://www.unifycommunity.com/wiki/index.php?title=GridMove ), and I notice the line:
"tx = t - 1.0; // Used to prevent slight visual hiccups on "grid lines" due to Time.deltaTime variance"
I believe this refers to what I'm noticing. What's more, is it isn't noticeable on all machines, as I believe it's caused by frame rates, it'll only be visible on slower frame rates.
Here's a sample of how I'm moving things (this is only for West, each direction has a different IF statement).
else if (actualBearing == 'West' && (grid[rowIndex][colIndex-1]) == 1) { west = true; moving = true; startPosition = transform.position; endPosition = transform.position + Vector3.right * stepDistance * -1; stepStartTime = Time.time; pivot() ; colIndex = colIndex-1; junction = true; realBearing = 'West'; } }else { var progress: float; progress = (Time.time - stepStartTime) / stepTime;
if (progress >= 1.0) {
transform.position = endPosition;
moving = false;
} else {
transform.position = Vector3.Lerp(startPosition, endPosition, progress);
pivot() ;
}
progress = progress -1.0;
}
Does anybody have an idea what's causing this?
Answer by Eric5h5 · Apr 11, 2011 at 04:11 AM
It's because the object's position is set to "endPosition" when it finishes moving, then it's set to "startPosition" (which is the same as the previous endPosition) for the next move, so it has the exact same position for two frames in a row. The more frames per second you have, the less noticeable this is, but the code in the GridMove script prevents that from happening in the first place. I'd recommend using that code for movement and applying the multidimensional array stuff on top, since having separate if statements for each direction is less than ideal (it's harder to maintain and more bug-prone than just having one set of code for movement).
Cheers, I'll try fixing it myself. I didn't want to use Gridmove because this is my first 3D game project, and first game using JavaScript. I'd rather learn myself, you see, and there's no educational gain copy+pasting a prebuilt system, y'know?