- Home /
iTween MoveTo
Hello :-)
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.
What type of game is this exactly, and what type of behavior are you expecting from Utilizing iTween? What do you mean by smoothly, as well? There could be several different definitions of "smooth" in terms of an tween curve.
If this is a real time character like a FPS and they'll be constantly strafing, I really don't see why you're trying to use iTween to do that.
This is a first person bull rushing game. The character is running away from a pack of bulls behind them and one of the actions the character can perform is strafing. Right now the character just snaps to the left or right when I press A or D. I want the character to smoothly strafe without teleporting essentially. Any input is appreciated.
Answer by DannyB · Oct 01, 2012 at 06:19 PM
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()
Answer by vanshika · Dec 18, 2013 at 06:14 AM
Try this.
iTween.MoveTo (gameObject, iTween.Hash ("x", 0 , "islocal", true, "time", 1.5 ,"looptype","none" , "easetype" , "spring"));
Answer by BLarentis · Oct 01, 2012 at 06:01 PM
You tried to set the ease type to linear, and adjust the time value to match your need ? Hope it helped. Take care !
Answer by Gurc · May 16, 2013 at 10:43 AM
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 () {
}
}
Your answer
Follow this Question
Related Questions
Using iTween to move a gameobject from node to node 1 Answer
Multiple Cars not working 1 Answer
iTween MoveTo doesn't move. [C#] 1 Answer
Distribute terrain in zones 3 Answers
Itween Problem 0 Answers