Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Scale animation causing jerky movement of Rigidbody2D

Discussion in '2D' started by malraux42, Feb 24, 2015.

  1. malraux42

    malraux42

    Joined:
    Jan 20, 2015
    Posts:
    5
    Hello,

    I ran into an issue using a scale animation on an object with a rigidbody. This problem happens with both LeanTween and iTween. The animation runs every second for a third of a second, and while the rigidbody is moving under the force of gravity it seems to halt during the animation.

    Add the following script to a Sprite, add a Rigidbody2D, set Interpolate to "interpolate", and set the gravity to 0.2 for easier viewing:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.UI;
    4. using System.Collections;
    5.  
    6. public class TestLeanTween : MonoBehaviour {
    7.     void Start () {
    8.         StartCoroutine(this.Grow());
    9.      }
    10.  
    11.     private IEnumerator Grow() {
    12.         float scale = 0.2f;
    13.         while (true) {
    14.             yield return new WaitForSeconds(0.7f);
    15.             scale += 0.1f;
    16.             LeanTween.scale (this.gameObject, new Vector3(scale, scale, 1), 0.3f);
    17.         }
    18.      }
    19. }
    20.  
    Place the Sprite on the screen up at the top and start the game. As the object falls, the downward motion will repeatedly pause while the scaling animation is active.

    Any ideas what might be causing this?

    Thanks,
    -scott
     
    Last edited: Mar 1, 2015
  2. PGJ

    PGJ

    Joined:
    Jan 21, 2014
    Posts:
    897
    I tried your example, and it runs just fine. The object falls without any stutters...
     
    malraux42 likes this.
  3. malraux42

    malraux42

    Joined:
    Jan 20, 2015
    Posts:
    5
    Thanks for trying it... very strange. Well, that's information I guess. Thanks again.
     
  4. malraux42

    malraux42

    Joined:
    Jan 20, 2015
    Posts:
    5
    I found the difference... set Interpolate on the Rigidbody2D to "interpolate" and the stuttering will occur.

    Setting it to "extrapolate" will make the sprite fall faster during the scale.