move smoothly without 'Time.deltaTime' ?

HI, community

After reading the document, I learn that , If one want to move objects smoothly , one should put some codes like the following into Update() function:

function Update () {
    // Move the object 10 meters per second!
    var translation = Time.deltaTime * 10;
    transform.Translate (0, 0, translation);
}

But how can I how can I acheive this without ‘Time.deltaTime’ and ‘Update()’ ?

For example,

object.transform.Translate(Vector3.left ); → this code will make object jump to left at once

object.TranslateSmoothly( Vector3.left , 1.0f ) → this What I want, object jump to left in 1 second, looks like sliding.

Sorry for my poor english.

Thanks.

First of all, moving objects should be done in the Update() function, that’s what it’s made for. You can use Vector3.Lerp or Vector3.Slerp or any of the other functions provided. Just have a look at the Vector3 (and for rotations Quaternion) entries in the Unity Documentation.

You need to use Time.deltaTime; there’s no way around it, and there’s no reason why you wouldn’t want to use it. If you’re talking about moving an object from one specific place to another, see here. In that case you’d use coroutines and not Update.

–Eric

If you really don’t want to use the update loop, you can do it in a coroutine (which still requires taking delta time into consideration) or you can just use a tweening library like iTween (which, as far as I know, works off of coroutines as well).

Sounds to me like you want iTween though: iTween for Unity by Bob Berkebile (pixelplacement)

With iTween you can do:

iTween.MoveTo(gameObject,Vector3(2,0,0),2);

Which is…

iTween.MoveTo(the object you want to move, the vector you want to move it by, the time you want to take it to get there);

You can also do all the other neat things that people expect from a tweening library (easing is a big thing here).

Thanks , iTween is the right choise .

hi!

i found that the hashtable inline javascript example shown on the iTween site won’t work with unity 3.5:

iTween.MoveTo(gameObject,{“x”:3,“time”:4,“delay”:1,“onupdate”,“myUpdateFunction”,“looptype”,“pingpong”});

got following error:

Assets/Scripts/buttons/objectMove.js(12,69): BCE0044: expecting :, found ‘,’.

i’m sure that’s something with new #pragma strict in unity - but i’m no coder, and have no idea how to fix this.

Has anybody an idea?

No, that’s just a syntax error, and wouldn’t work with any version of Unity. As it says, it was expecting a colon but found a comma. Should be “onupdate”:“myUpdateFunction”, “looptype”:“pingpong”.

–Eric

link doesn’t work for me anymore.

Well, the link is 8 years old.

Though @Eric5h5 , do you know who we should get in touch with about the whole “all the old links to unify now leads to virus hell and there’s a million of those links on the forums and Unity Answers” issue? Because it’s a problem.

@OwnDemise , you’ll want to start a coroutine to move the object, or use a tweening library. That should give you a good googling base.

UnifyWiki needs to be taken out back and shot to be completely frank. Even if you avoid the viruses the best you find will be outdated, obsolete code samples. It hasn’t been useful for about a decade now.

I have no idea; last I head, Unity wanted to preserve the site, but I guess that didn’t happen.

–Eric