Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Animating scale with gravity, jerky motion

Discussion in 'Physics' started by malraux42, Feb 15, 2015.

  1. malraux42


    Jan 20, 2015

    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, and set the gravity to 0.2 for easier viewing:

    Code (csharp):
    2. using UnityEngine;
    3. using UnityEngine.UI;
    4. using System.Collections;
    6. public class TestLeanTween : MonoBehaviour {
    7.     void Start () {
    8.         StartCoroutine(this.Grow());
    9.      }
    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, newVector3(scale, scale, 1), 0.3f);
    17.         }
    18.      }
    19. }
    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?

    Last edited: Mar 1, 2015