- Home /
Change Position of an object
I have this script, but I want the object to move slowly, not instant. I tried with * Time.deltatime, but it doesn't work. How can i do that??
var destination : Transform; var destination2 : Transform; var firstperson : boolean; function Update () { if (!firstperson) { if(Input.GetButtonDown("Cam")) { transform.position = destination.position * Time.deltatime; firstperson = true; } } if (firstperson) { if(Input.GetButtonDown("Cam2")) { transform.position = destination2.position; firstperson = false; } } }
Next time please google your question, this has been answered many times: http://answers.unity3d.com/questions/187588/move-from-one-point-to-another.html I hope it helps
thanks, but this is for pingpong. I want to do it only one time
if i use ping pong it does it continiously, I'm noob, sorry!!!
Answer by Noah-1 · Oct 23, 2012 at 07:45 PM
Ok then, Vector3.Lerp should do the trick:
Create an empty gameObject for start point, other for end point and assign them in the inspector.
var start : Transform;
var end : Transform;
function Update () {
transform.position = Vector3.Lerp(start.position, end.position, Time.time);
}
hope that helps you, and don't apologize for being a "noob", everyone was one before. If you want it to be slower you can simply divide time (Time.time/2).
Thanks it worked! But when I add an Input.... itgoes immediatly from one point to another
var start : Transform; var end : Transform;
function Update () { if(Input.$$anonymous$$ouseButtonDown(1)) { transform.position = Vector3.Lerp(start.position, end.position, Time.time); } }