Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by nzshapeshifter · Nov 19, 2013 at 06:30 PM · arraytouchitweenfollowvectrosity

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() );
     }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

Camera rotation around player while following. 6 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges