How do I stop transform.Translate using time?
I am sure this is a basic question. I've only had two classes using Unity and one of our assignments is to...
There must be at least three moving objects.
They should not all move the same way.
**Time must be involved in some way (beyond constant motion) - stop the motion after a certain time, don't start the motion until a certain time, or something else.**
I just can't figure out how to do the third part. How do I stop the constant motion? Again, only been in class for two days. I'm brand new. Do I use an if statement with time?
Please help. I'd be so grateful. Again, I'm sorry for such a basic question.
Answer by cjdev · Sep 08, 2015 at 10:36 AM
You were on the right track with an if statement, all you'd need to do is check the value of your time variable and move when the time is valid.
if (time < 5f)
{
//Move when time is less than 5 seconds
}
Another idea could be setting some axis of motion of the object to:
$$anonymous$$athf.Sin(Time.time*2*$$anonymous$$athf.PI)
or
$$anonymous$$athf.PingPong(Time.time, 5)
or
if(time > 1){
$$anonymous$$athf.Log(Time.time)
}
Basically look up $$anonymous$$athf unity... it is useful for non-constant motion!
Answer by kabehzad · Sep 09, 2015 at 01:00 AM
@cjdev - I'm trying to use the time function but where does it come in the script relative to the rest of the code? It keeps giving me an error.
var speed : float = 5.0;
function Update() {
transform.Translate(Vector3(0,0,speed) * Time.deltaTime);
}
What is the error you are getting, if you copy and paste cjdev's code you will get one because the variable 'time' is unknown to unity, you have to google some stuff or find the useful things in the same Time class as you have already made use of.
Your answer
Follow this Question
Related Questions
Limit movement to just forward/backward and left/right 0 Answers
Limit movement to just forward/backward and left/right 0 Answers
transform.Translate() effect is being reverted 0 Answers
Trying to make sliding doors. With transform, but it jumps to position. What am I doing wrong? 1 Answer
Moving an object smoothly over predetermined distance without defining begin and end points 0 Answers