0
\$\begingroup\$

I have set an itween path for an object to move.And I have written the code as

iTween.MoveTo(gameObject,iTween.Hash ("path",iTweenPath.GetPath("train"),"time",300));

The above code is working for me.

Now I need to apply the change in speed that mean,when i press "S" the object should move Slow,when I press "F" the object should move Fast,When I press "M" the object should move with a medium speed on the itween path.I have written a code for.Below is the code

void Update () {

    if(Input.GetKey(KeyCode.S))
    {
        iTween.MoveTo(gameObject,iTween.Hash ("path",iTweenPath.GetPath("train"),"time",300));

    }
    if(Input.GetKey(KeyCode.M))
    {
        iTween.MoveTo(gameObject,iTween.Hash ("path",iTweenPath.GetPath("train"),"time",100));

    }
    if(Input.GetKey(KeyCode.F))
    {
        iTween.MoveTo(gameObject,iTween.Hash ("path",iTweenPath.GetPath("train"),"time",50));

    }
}

When I runned my above code,and when I press "S" key its moving slowly,next when I press "F" the object is going back to the original position where it was and then it starts moving fast ,same as for the medium "M" also.

I need to change the speed of the object moving on the itween path specified by pressing the keys.Can anybody please help me out.

\$\endgroup\$
-1
\$\begingroup\$

According to the documentation, you can pass a speed argument.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ how to apply the methods through code \$\endgroup\$ – user1509674 Mar 16 '15 at 9:04
  • \$\begingroup\$ iTween.MoveBy(gameObject, iTween.Hash("x", 2, "speed", 0.1)); based on what key you have pressed you can change value of speed. \$\endgroup\$ – 2600th Mar 16 '15 at 9:19
  • \$\begingroup\$ i gave the above code on my keypress but its not working \$\endgroup\$ – user1509674 Mar 16 '15 at 9:27
  • \$\begingroup\$ I couldn't get it working . \$\endgroup\$ – user1509674 Mar 17 '15 at 12:17
-1
\$\begingroup\$

This will set the speed to 8:

Hashtable props = new Hashtable();
props.Add("path", iTweenPath.GetPath("train"));
props.Add("speed", 8f);

iTween.MoveTo(gameObject, props)

I like to create a hashtable with all the properties I want to set, then pass it in at a later date. It is of course a matter of preference; I just think it makes things look clearer.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.