For a general vertical upward throwing motion, the highest point is reached when the velocity is 0. We have:
$$ S=\frac{v^{2}}{2g},t=\frac{v}{g} $$
Let the factors of velocity and gravity be a
and b
respectively:
$$ v'=av,g'=bg $$
Now we need the height to be the same and the time to expand n
times
$$ S'=\frac{v'^{2}}{2g'}=\frac{a^{2}v^{2}}{2bg}=S=\frac{v^{2}}{2g} $$ $$ t'=\frac{v'}{g'}=\frac{av}{bg}=n·t=n·\frac{v}{g} $$ So we get: $$ a^{2}=b $$ $$ a=n·b $$ And: $$ a=\frac{1}{n},b=\frac{1}{n^{2}}(a,b,n,g≠0) $$
C# code:
using UnityEngine;
public class UnscaledObject : MonoBehaviour
{
private Rigidbody2D rigidbody;
private float factorA =1f;
}
private void Start()
{
rigidbody = GetComponent<Rigidbody2D>();
}
private void SetTimeScale(float n)
{
factorA = 1/n;
var factorB = factorA*factorA
rigidbody.gravityScale = factorB;
}
private void SetVelocity(Vector2 v)
{
rigidbody.velocity = factorA * v;
}