• 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
Question by Zip · Mar 19, 2013 at 02:27 AM · pathfindingitweenpathnodesmoveto

iTween, moving to a node on a path.

I'm making a board game and I decided to try and use iTween for the pathing around the board. I have 42 tiles around my board, each with it's own node. I can get the gameObject to go completely around the path, but I'm lost at how to get it to only move to the node I need it to. I'm using a dice in the game to deiced how many spots the gameObject is to move if that makes a difference.

Would really appreciate any help, an example of a scenario would be if the game object was on node 3 and rolled a 6 it would go to node 9.

Note: I'm writing this in javascript.

Comment

People who like this

0 Show 1
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
avatar image Zip · Mar 19, 2013 at 02:47 AM 0
Share

there's only one node per game position. in this picture each of those dots has it's own node. http://i.imgur.com/fd7ODyw.jpg

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by robertbu · Mar 19, 2013 at 03:20 AM

I should have read the question more carefully since you say "each with it's own node." Anyway, if you can move around the whole path, somewhere you have an array of either Vector3s or Transforms that you pass to iTween. Since you have a singe ordered path you can extract any part of it to build a list of Vector3s to pass to iTween. Note you should label your positions starting with 0. I'm using arv3AllPos as a list the list for the whole path. You array will have a different name. MakePath extracts any specified segment out of the total array to use as the path for a player move on the roll of the dice.

 var arv3AllPos : Vector3[];
 
 function MakePath(startNode : int, endNode : int) : Vector3[] {
 
     var v3New = new Vector3[endNode - startNode + 1];
     for (var i = startNode; i <= endNode; i++)
         v3New[i-startNode] = arv3AllPos[i];
         
     return v3New; 
 }
Comment

People who like this

0 Show 4 · Share
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
avatar image Zip · Mar 19, 2013 at 10:58 AM 0
Share

This is just what I needed, I'll try it out when I get home but it looks perfect. I'll let you know if it worked soon. Thanks you.

avatar image Zip · Mar 19, 2013 at 04:05 PM 0
Share

I'm really close to getting it I just need a little more help with it. Right now as a test I'm using this as my code:

     var Pathcoords : Vector3[];
     Pathcoords[1]=Vector3(85.2, 7.41 ,117.4);
     Pathcoords[2]=Vector3(85.7, 7.41 ,121.8);
     Pathcoords[3]=Vector3(85.7, 7.41 ,126.0);
     Pathcoords[4]=Vector3(86.7, 7.41 ,130.8);
     Pathcoords[5]=Vector3(87.0, 7.41 ,134.8);
     Pathcoords[6]=Vector3(87.8, 7.41 ,138.7);
     
      
     function MakePath(startNode : int, endNode : int) : Vector3[] {
      
     var v3New = new Vector3[endNode - startNode + 1];
     
     for (var i = startNode; i <= endNode; i++)
     v3New[i-startNode] = Pathcoords[i];
    
 
      
     return v3New;
 
     }
     
     
     
     
 function Start () {
    var v3path:Vector3[] = MakePath(1,3);
     iTween.MoveTo(gameObject,v3path[0],1);
     iTween.MoveTo(gameObject,v3path[1],1);
     iTween.MoveTo(gameObject,v3path[2],1);
 
 
 
 }









When running this code I get two IndexOutOfRangeException: Array index is out of range errors. I feel like I should be defining the size of the arrays but can't figure out how for some reason.

here's the exact errors I get:

IndexOutOfRangeException: Array index is out of range. player1.MakePath (Int32 startNode, Int32 endNode) (at Assets/Scripts/player1.js:20) player1.Start () (at Assets/Scripts/player1.js:32)

and

IndexOutOfRangeException: Array index is out of range. player1.Main () (at Assets/Scripts/player1.js:7)

I know this is a really simple problem but I'm new to javascript and just can't see what's wrong. Thanks you for your help.

avatar image robertbu · Mar 19, 2013 at 04:34 PM 0
Share

You need to create the memory for the array, not just declare the variable. For example:

 var Pathcoords : Vector3[] = new Vector3[50];

You an also modify it in the Inspector instead. If you click on the object this script is attached to, in the Inspector you will see a triangle next to Pathcoords. You can click on the triangle to open it up. Set it size, and then you can enter the values in the inspector. If you don't want to use the inspector, I recommend making the variable private:

 private var Pathcoords : Vector3[] = new Vector3[50];
avatar image Zip · Mar 19, 2013 at 04:41 PM 0
Share

Excellent, everything is working the way I want it to. You have my thanks. I really appreciate all the help.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

Scale an iTweenPath 0 Answers

iTween MoveTo + Rotation? 2 Answers

Go back to first node (itween + moveto) 2 Answers

A* pathfinding, Re checking nodes 1 Answer

iTweens MoveTo and "path" property 7 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