- Home /
Interpolation issue, some items not being interpolated correctly.
I have a game in which you break through obstacles and the obstacle parts separate into physics based pieces.
All of the pieces are contained in the parent object, they all have rigidbody2d on them, set as kinematic and no interpolation. Once they break apart, I turn off kinematic and turn on interpolation for smooth movement. This works great right now and the game is running amazingly with a lot of obstacles on screen.
The problem is, when there is a lot of obstacles, and a few of them are broken apart, some of the pieces are very jittery and act as though they are not being interpolated, while some (even from the same parent) are smooth as butter.
I wonder if this is an interpolation restriction, like maybe only a certain number of things are meant to ever be interpolated at a time?
Here is the code I'm using.
void OnTriggerEnter2D (Collider2D col) {
if (col.tag == "Shockwave" && gameObject.tag != "Transition") {
if (spin != null) {
spin.spinning = false;
}
if (!isShard) {
obstacleCol.enabled = false;
objDespawn.enabled = false;
SeparateObject ();
} else {
obstacleCol.isTrigger = false;
}
worldStats.totalObstaclesDestroyed ++;
}
if (col.tag == "Blast" && gameObject.tag != "Transition") {
if (spin != null) {
spin.spinning = false;
}
if (!isShard) {
obstacleCol.enabled = false;
objDespawn.enabled = false;
SeparateObject ();
} else {
obstacleCol.isTrigger = false;
}
worldStats.totalObstaclesDestroyed ++;
}
}
void SeparateObject ()
{
foreach (Transform shard in shards) {
if (shard.GetComponent<Collider2D> ()) {
shard.GetComponent<Collider2D> ().enabled = true;
}
if (shard.GetComponent<Rigidbody2D> ()) {
Rigidbody2D rb = shard.GetComponent<Rigidbody2D> ();
rb.isKinematic = false;
rb.interpolation = RigidbodyInterpolation2D.Interpolate;
}
}
}
How are you moving them, with a script or an animation? If they're kinematic then they're not being updated by the physics.
If you set your time settings to a fixed timestep of 0.0166666 and maximum allowed timestep to 0.01666666 does the problem go away? With those settings you shouldn't need interpolation enabled.
They are being moved while kinematic is active through their parent, not by physics (maybe i should not even have a rigidbody on them at this point?) The parent is simply moving by transform.position. Once they are separated from the parent (after player hits parent), i turn kinematic off and let physics take over for each part, this is also where I turn on interpolate.
I'll try what you said about the timestep. Will that work if the framerate changes though? $$anonymous$$aybe that is not a big deal since I am getting a pretty s$$anonymous$$dy 60fps.
With those settings the game will slow down if the frame rate drops, it'll be like going into slow motion for a bit. It will always be smooth though.
To be honest the jittering is probably due to something other than the interpolation, but it'd be good to rule that out.
So I came back to this problem after ignoring it for a bit. I still don't have it figured out, but I now am under the impression that it isn't a problem with the Interpolation. I turned interpolation on by default, same problem.
Here is where I am at now, in case anyone is interested... I have a player and obstacles he has to avoid, if they player hits an obstacle, the obstacle separates into pieces that go flying. This works great, when I hit an obstacle, it separates well and interpolation is working as it should. Now, what I also do, is send out a shockwave that hits surrounding obstacles. The same code is applied to these to separate them, but it's the shockwave collider trigger that is setting this in motion. This seems to be where the issue is. Imagine a giant circle around the player turning on for a split second and whatever is in that circle is destroyed. Anything that is destroyed this way, has jittery movement. When I pause the game however, these pieces have all the same properties that a working peice does.
Hey Taylor, I think you'll need to post some code to get an answer to this.