- Home /
Calculating translation speed?
Hello. As the reference example says, using this code will translate an object forward 1 unit, but what if I have some odd values for how fast I want the object to move? Example: I want an object that is scaled (.5,.5,.5) and I want it to move 2.3 units forward every 5 seconds? * I know there are ways to move an object to a specific point in a specific amount of time (such as iTween or this), but I want to be able to have that object reach that point in a specific time...but then keep moving along at that speed. Thanks
function Update() {
transform.Translate(Vector3.up * Time.deltaTime, Space.World);
}
Thanks
Just add a 'speed' multiplier into your translation command:
var speed : float = 2.3;
transform.Translate(Vector3.up * Time.deltaTime * speed, Space.World);
Answer by Peter G · Jan 25, 2012 at 04:14 AM
This is really simple math. You need a rate:
Distance = Rate * Time
Solve for rate:
Rate = Distance / Time
So you need to move based on your rate:
var distance : float;
var time : float;
function Update () {
transform.Translate( Vector3.up * Time.deltaTime * distance / time , Space.World);
}
For your individual example set distance to 2.3 and time to 5.
And that should solve all your problems.
Your answer
![](https://koobas.hobune.stream/wayback/20220613063351im_/https://answers.unity.com/themes/thub/images/avi.jpg)