TSTransform2D interpolation bug fix

I was wondering if there's a public git repo or something I can submit a pull request to? I have a bug fix for the TSTransform2D class. If not, I can just paste the code change here.


  • WhaleFood
    edited September 2017
    Either way, here's the code. This fixes the Interpolate and Extrapolate options (at least for position) from a TSRigidBody2D.
    private void UpdatePlayMode() {
    			if (rb != null)
                    if (rb.interpolation == TSRigidBody2D.InterpolateMode.Interpolate) {
                        var lerpAmount = (float)((Time.time - TrueSyncManager.Time) / TrueSyncManager.TrueSyncGlobalConfig.lockedTimeStep);
                        transform.position = Vector3.Lerp(transform.position, position.ToVector(), lerpAmount);
                        transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(0, 0, rotation.AsFloat()), lerpAmount);
                        transform.localScale = Vector3.Lerp(transform.localScale, scale.ToVector(), lerpAmount);
                    } else if (rb.interpolation == TSRigidBody2D.InterpolateMode.Extrapolate) {
                        transform.position = (position + tsCollider.Body.TSLinearVelocity * Time.deltaTime).ToVector();
                        transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(0, 0, rotation.AsFloat()), Time.deltaTime * DELTA_TIME_FACTOR);
                        transform.localScale = Vector3.Lerp(transform.localScale, scale.ToVector(), Time.deltaTime * DELTA_TIME_FACTOR);
                transform.position = position.ToVector();
                Quaternion rot = transform.rotation;
                rot.eulerAngles = new Vector3(0, 0, rotation.AsFloat());
                transform.rotation = rot;
                transform.localScale = scale.ToVector();
  • Can't find where to edit my response, but a small correction: should be TrueSyncManager.Config.lockedTimeStep instead of TrueSyncManager.TrueSyncGlobalConfig.lockedTimeStep
  • Thanks @WhaleFood, we don't have a public repo but thanks for sharing.
  • Sorry. Realized my code is still off because Time.time and TrueSyncManager.Time don't necessarily start together. I was able to finally fix it, but my solution is a bit too messy to share.