Hi I have created 2 paths using Itween. Path0 is Vertical and Path1 is horizontal. Path1 intersects Path0 somewhere in the middle.
How do I ensure that the gameobject can only move right/left while it is on Path1 and since Path1 and Path0 are intersecting each other there is a point where the gameobject can move in all 4 directons. Currently, my gameobject just jumps to Path1 from Path0 when I press the right key while gameobject is on path0. please help!
public class itweenObject : MonoBehaviour {
public Transform[] path0;
public Transform[] path1;
private float percent0;
private float percent1;
public Collider2D cornerTrigger1 = null;
void OnDrawGizmos(){
iTween.DrawPath(path0,Color.blue);
iTween.DrawPath(path1,Color.blue);
}
void Update () {
if(Input.GetKey(KeyCode.UpArrow))
{
percent0 += Time.deltaTime;
iTween.PutOnPath(this.gameObject,path0, percent0);
}
else if(Input.GetKey(KeyCode.DownArrow))
{
percent0 -= Time.deltaTime;
iTween.PutOnPath(this.gameObject,path0, percent0);
}
if(Input.GetKey(KeyCode.RightArrow))
{
percent1 += Time.deltaTime;
iTween.PutOnPath(this.gameObject,path1, percent1);
}
else if(Input.GetKey(KeyCode.LeftArrow))
{
percent1 -= Time.deltaTime;
iTween.PutOnPath(this.gameObject,path1, percent1);
}
}
}
↧