iTween MoveTo

Hello :slight_smile:

I’m trying to get my game object to strafe SMOOTHLY. Here’s my code:

using UnityEngine;
using System.Collections;

public class MoveTo : MonoBehaviour {

	
	// Update is called once per frame
	void Update () {
		
		if (Input.GetKeyDown(KeyCode.A))
			iTween.MoveTo(gameObject,iTween.Hash("position",transform.position += Vector3.left*2,"easetype",iTween.EaseType.easeInOutSine,"time",.2f));
		
		if (Input.GetKeyDown(KeyCode.D))
			iTween.MoveTo(gameObject,iTween.Hash("position",transform.position += Vector3.right*2,"easetype",iTween.EaseType.easeInSine,"time",.2f));
	
	}
}

I noticed that if I set my “time” parameter to a higher number such as 3 and press one of the input keys twice within those three seconds the object will move smoothly. Maybe that’ll help one of you understand what the computer is thinking.

Any help is appreciated.

Why are you using “transform.position += value” as an argument to iTween?

You are both asking iTween to move the object for you, and you are moving it yourself.
Try using a fixed value there, and use MoveBy instead (unless MoveTo is really what you need).

Also, if you want to move on one axis only, use “X” or “y” instead of “position”.

iTween.MoveBy(gameObject,iTween.Hash(
	"x"   , 2,
	"time", 0.2f
));

Finally, for a situation such as yours, where you want (I presume) to move the player only while the key is pressed, you should probably avoid “one shot” tweens, and instead use either one of the iTween Update methods (e.g. MoveUpdate), or avoid iTween altogether (for this case) and use transform.Translate()

Try this.

   iTween.MoveTo (gameObject, iTween.Hash ("x", 0 , "islocal", true, "time", 1.5 ,"looptype","none" , "easetype" , "spring"));

You tried to set the ease type to linear, and adjust the time value to match your need ? Hope it helped. Take care !

You must call iTween once. You call it each update. For example

public class doubleTween : MonoBehaviour {

	// Use this for initialization
	void Start () {
		iTween.RotateBy(gameObject,iTween.Hash("x", .25,"time",2, "easeType"
			, "easeInOutQuad", "loopType", "pingPong", "delay", .2));
		
		iTween.MoveTo(gameObject,iTween.Hash("x",6,"time",4,"loopType","pingPong"
			,"delay",.4,"easeType","easeInOutQuad"));
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}