Question by
$$anonymous$$ · Jul 20, 2020 at 12:46 PM ·
rigidbody2dscaledown
2D Objects have weird behaviour when scaling the platform under them
So in short, i have a circle with a rigidbody2d to make it fall, when i change the size of the platform under it ( basically scale it up and down), i notice that when the platform scale down the circle bounce and the more size difference between max and min, the more bouncy the circle is, performance error i guess ? or do i do something wrong.
Here my platform scaling script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Scaling : MonoBehaviour
{
public Vector3 minScale;
private Vector3 maxScale;
public bool Repeatable;
public float speed = 2f;
public float duration = 10f;
public static Scaling instance;
private void Start()
{
instance = this;
StartCoroutine(StartScaleing());
}
public IEnumerator StartScaleing()
{
maxScale = transform.localScale;
while (Repeatable)
{
yield return RepeatLerp(maxScale , minScale, duration);
yield return RepeatLerp(minScale, maxScale, duration);
}
}
private IEnumerator RepeatLerp(Vector3 x, Vector3 y, float time)
{
float i = 0f;
float rate = (1 / time * speed);
while (i < 1f)
{
i += Time.deltaTime * rate;
transform.localScale = Vector3.Lerp(x, y, i);
yield return null;
}
}
}
Comment
Your answer