0

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 the motion seems to halt during the animation.

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

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class TestLeanTween : MonoBehaviour {
    void Start () {
        StartCoroutine(this.Grow());
     }

    private IEnumerator Grow() {
        float scale = 0.2f;
        while (true) {
            yield return new WaitForSeconds(0.7f);
            scale += 0.1f;
            LeanTween.scale (this.gameObject, new Vector3(scale, scale, 1), 0.3f);
        }
     }
}

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. If interpolate is set to "extrapolate", the sprite will fall faster during the scaling animation.

Any ideas what might be causing this behavior?

Scott A
  • 7,745
  • 3
  • 33
  • 46

2 Answers2

0

As mentioned in Unity - Manual: Rigidbody

Changing the Transform while using physics could cause problems with collisions and other calculations.

Also read the Use the right size section on the above link.

When you change the scale of your GameObject it effects the calculations of RigidBody/ Physics in your game.

A possible way around:

Create an empty GameObject and attach you RigidBody and colliders to it. Add your 'object' (the one you want to apply animations on) as a child inside the new GameObject (remove RigidBody and colliders from your object after adding it as a child or it may cause further problems). Once done now animate the scale of your child object leaving the parent (having RigidBody component) alone.

user229044
  • 232,980
  • 40
  • 330
  • 338
Anas iqbal
  • 1,036
  • 8
  • 23
0

You can scale only mesh, without scale other components. This will resolve your issue. (meed to crete empty child object)

Andrew_STOP_RU_WAR_IN_UA
  • 9,318
  • 5
  • 65
  • 101