- Home /
I need to travel the same distance in less than 1 second
Hi ! Currently I move a ball forward to a certain distance at Time.deltaTime.
transform.Translate(transform.forward * 1.7118f * Time.deltaTime);
I don't know how I can move the same distance in 0.8 seconds. I tried to mulitply with 1.2f as it seemed logical to me but with no success...
EDIT : @Roger_0123 I still have the same problem, I guess it does not come from this bit of code. I have a dotween sequence that handle the Y value :
sec.Append(transform.DOMoveY(5.1f, speedUp)).SetEase(Ease.InQuad);
sec.Append(transform.DOMoveY(3f,speedDown)).SetEase(Ease.InQuad);
sec.SetLoops(-1, LoopType.Restart);
I change the speed values when my ball hit the floor :
float ratio = initSpeedUp / initSpeedDown;
speedDown -= 0.05f / ratio;
speedUp -= 0.05f;
And finally I use the translate on Z :
transform.Translate(transform.forward * (1.7118f / (speedDown + speedUp)) * Time.deltaTime);
Currently, the ball does gain speed but the rebounds don't follow so I fly above a greater distance than intended...
Answer by Roger_0123 · Sep 11, 2020 at 07:31 AM
@Steyo It should work as you wrote. The correct formula is: transform.Translate(direction * 1 / (your_time) * Time.deltaTime)
Then my problem must come from the calculation of "your_time", thx.