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 ()) {
shard.GetComponent ().enabled = true;
}
if (shard.GetComponent ()) {
Rigidbody2D rb = shard.GetComponent ();
rb.isKinematic = false;
rb.interpolation = RigidbodyInterpolation2D.Interpolate;
}
}
}
↧