- Home /
Can you use a Vectrosity points array with iTween?
So I have made a script which draws lines by user touch input with Vectrosity. Then adds an object to the line which follows it. However I am having some trouble with controlling the speed at which the object travels and also when it actually starts to move. Basically the object doesn't start moving until the count is over x percent of the array length. At least I think thats the problem but my code fu isn't that strong. So I thought by moving the object through iTween I could regain the control with something like MoveTo(object, vectorLineArray, whateverSpeed). But I am at a loss as to how to implement it and can't find much online in the way of merging Vectrosity with iTween. If anyone could help with either getting iTween and Vectrosity to cooperate or even just a better way to move the object which solves my original problem that would be great. Cheers
import Vectrosity;
var lineMaterial : Material;
var maxPoints = 500;
var lineWidth = 4.0;
var minPixelMove = 5; // Must move at least this many pixels per sample for a new segment to be recorded
var transformHeight = 200.0;
var guiX = 10.0;
private var linePoints : Vector2[];
private var line : VectorLine;
private var touch : Touch;
private var lineIndex = 0;
private var previousPosition : Vector2;
private var sqrMinPixelMove : int;
private var canDraw = false;
private var splinePoint : Vector2;
private var count : float = 0.0;
private var arrayLength: float;
var cube : Transform;
var speed = .05;
private var loop = false;
var ButPress = false;
private var dist = 0.0;
function Start ()
{
linePoints = new Vector2[maxPoints];
sqrMinPixelMove = minPixelMove*minPixelMove;
//line.drawEnd = lineIndex;
}
function Update ()
{
if (Input.touchCount > 0)
{
touch = Input.GetTouch(0);
if (ButPress && touch.phase == TouchPhase.Moved && (touch.position - previousPosition).sqrMagnitude > sqrMinPixelMove && canDraw)
{
previousPosition = linePoints[++lineIndex] = touch.position;
line.minDrawIndex = lineIndex-1;
line.maxDrawIndex = lineIndex;
line.drawStart = lineIndex - (lineIndex - 1);
if (lineIndex >= maxPoints-1) canDraw = false;
line.Draw();
}
else if (ButPress && touch.phase == TouchPhase.Ended)
{
line.SetDistances();
line.drawEnd = lineIndex;
//loop = true;
arrayLength = line.GetLength();
ButPress = false;
}
}
if (loop)
{
if (count <= arrayLength)
{
splinePoint = line.GetPoint(count);
cube.position = Camera.main.ScreenToWorldPoint (Vector3 (splinePoint.x, splinePoint.y, transformHeight) );
count += Time.deltaTime*speed;
}
if (count > arrayLength)
{
loop = false;
}
}
//Debug.Log("Time * Speed = " + Time.deltaTime * speed);
//Debug.Log(dist);
}
///Called when cube is selected
public function buttonPress ()
{
VectorLine.Destroy(line);
line = new VectorLine("DrawnLine", linePoints, lineMaterial, lineWidth, LineType.Continuous, Joins.Weld);
loop = false;
dist = 0.0;
ButPress = true;
line.ZeroPoints();
line.minDrawIndex = 0;
line.drawStart = 1;
line.Draw();
previousPosition = linePoints[0] = touch.position;
lineIndex = 0;
canDraw = true;
}
///Called when timer hits zero
public function timerComplete()
{
//dist = 0.3;
loop = true;
Debug.Log("Cube move start");
}
///Called when objects collide
public function characterCollision()
{
Debug.Log("Hit2");
var collisionHold = line.GetPoint01(dist);
cube.position = Camera.main.ScreenToWorldPoint (Vector3(collisionHold.x, collisionHold.y, transformHeight));
loop = false;
}
public function OnGUI()
{
GUI.Box( Rect(guiX, 100, 100, 20), previousPosition.ToString() );
GUI.Box( Rect(guiX, 150, 100, 20), count.ToString() );
GUI.Box( Rect(guiX, 200, 100, 20), (Time.deltaTime).ToString() );
GUI.Box( Rect(guiX, 250, 100, 20), splinePoint.ToString() );
GUI.Box( Rect(guiX, 300, 100, 20), arrayLength.ToString() );
}
Your answer
Follow this Question
Related Questions
Player not following touch after camera is rotated? 0 Answers
iTween - Path Movement by Touch 0 Answers
Door Script Help! 0 Answers
How to make 2 or more Objects to follow 2 or more fingers 1 Answer