- Home /
Transform.Translate change distance and speed
So basically in my experience with transform.translate you can basically choose how fast it goes. For example, transform.Translate (Vector3(-1,0,0) * Time.deltaTime*distance);, if i had a variable called distance it wouldn't change the distance, it would just change the speed on how fast it would go. So basically i have a randomized variable and i want it to go the same speed, but different distances. So should i not use transform.translate or is there something else that i should probably use because i want the same speed but different distances.
Answer by Kiwasi · Jul 15, 2014 at 05:28 AM
Distance is a function of speed and time. So if you want the same speed and different distances then you simply need to let the code run for longer.
So how do i change the amount of time the code is running based on a variable. Because i have a randomized variable but i want it to go that distance.
Division.
Seriously though you might want to take a look at Vector3.$$anonymous$$oveTowards.
I dont know if i can do that, because i want the distance changed by the variable, not a given point. I looked at $$anonymous$$oveTowards and it doesn't look likely because i need to make it go left and right. I just need like transform.translate that goes a certain distance based on a variable, the movetowards looks like its based on steps and a pre deter$$anonymous$$ed transform
... You should take up stamp collecting, its likely to be a more enjoyable hobby.
However, if your willing to persist, I'm willing to help. There are a number of ways to make code run for a set period of time. I'll show you how to do a custom timer. You should also look up coroutines. The timer shown below will work for 3 seconds. (C#)
private float timer = 3;
void Update (){
if (times > 0){
timer = timer - Time.deltaTime;
// Do your move function here
}
}
Thanks, I made this question with the $$anonymous$$dset that you could calculate a specific point based on current location and make the object move over time. I didn't really have the $$anonymous$$dset with time, so thanks for giving me that snippit of code it helps even though im using javascript it made me realize what i was doing wrong
Your answer
![](https://koobas.hobune.stream/wayback/20220613154105im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Player Transformation 2 Answers
Move an object to a specific point? 1 Answer
How to translate object one movement with script 1 Answer
LookAt transform plus a y value 1 Answer
Move object to raycast point. 3 Answers