- Home /
Question by
Digitaljedi · Feb 25, 2012 at 03:11 AM ·
javascript
Pain in the ass
I am trying to get a 3d text to move left -10 on the x axis in 1 second on a click in javascript but all atempts have failed and i am getting really pissed. Can anyone help?
Comment
Answer by Eric5h5 · Feb 25, 2012 at 08:19 AM
http://www.unifycommunity.com/wiki/index.php?title=MoveObject
I must say "Pain is the ass" is a very unhelpful title. Something like "Moving an object a certain distance over time" would be better.
Answer by jaised · Feb 25, 2012 at 06:42 AM
I think this might get you close to where you are wanting to go. It's a rough sketch (not tested). Good luck!
// example: slide(Vector3(-10, 0, 0), 1)
function slide(howMuchToSlide : Vector3, howLongWillItTake : float) {
var timeSpent : float = 0.0;
// keep moving until time is up
while(timeSpend < howLongWillItTake) {
// update our time counter
timeSpent += Time.deltaTime;
// breaks total movement into however many steps needed to cover that
// distance within the time limit specified
var step = howMuchToSlide / howLongWillItTake;
// then move the object by that total step movement
transform.Translate(step * Time.deltaTime);
// make sure to wait for that long to make sure it takes effect
yield WaitForSeconds(step * Time.deltaTime);
}
}