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 ATMEthan · Nov 27, 2012 at 05:21 PM · c#itweenitweenpathmoveto

Using iTween to move a gameobject from node to node

Hello all,

I am using the iTween path for a level select menu. I have the path nodes set up to the location of the level buttons. I have a user icon that I want to move from node to node when the level button is pressed. I've tried using the documentation and other forum posts but I wasn't getting anywhere fast! So, my user icon starts on level 1. When I click level 6 I want the user icon to travel the path of the iTweenPath until it gets to the sixth node(same location as the level 6 button). How can I accomplish that? I would post my code but its pointless b/c its very broken. I came close to what I want with this code but the user icon gameobject displayed very wierd behavior(usericon transporting around the scene).

Before trying the .moveto() method I was using the .putonpath() which just teleported the usericon to the button location. It was great minus the fact it didn't walk there. Any suggestions?? If you need code I'll upload it but like I said before it really doesn't work at all.

Also, I got the moveto to work but the usericon wouldn't move along the iTweenPath it would just pan from button location to button location

Update 1: Ok, so I got close to what I want.

 iTween.MoveTo(userIcon.gameObject, iTween.Hash("position", new Vector3(worldPath.nodes[moveDestination].x, worldPath.nodes[moveDestination].y, 0.0f), "path", iTweenPath.GetPath("World0Path"), "movetopath", false, "time", 5.0f, "looptype", "pingPong"));

This line of code moves the usericon along the path but it always moves it to the last node in the iTweenPath. I thought I could use the position parameter to be the end position but clearly I was wrong.

Update 2: The iTween documentation says the position arg is supposed to be the "for a point in space the GameObject will animate to." With my line of code(still the one from above) no matter what I set the position arg to be it still always ends at the end of the iTweenPath http://itween.pixelplacement.com/documentation.php

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Screenhog · Nov 27, 2012 at 06:54 PM

The key to this is to give it the correct path.

Right now, you're always giving it the same path, right? (iTweenPath.GetPath("World0Path")) Instead, give it only the nodes it needs.

 var nodes: Vector3[]; //master list of all nodes, in order
 var path: Vector3[]; //the path that you will use for iTween
 
 function ChoosePath (pathStart: int, pathEnd: int) {
     path = new Vector3[Mathf.Abs(pathEnd-pathStart)+1];
     //make the path move in the opposite direction is pathStart is greater than pathEnd
     var sign: int; //negative or positive value
     if (pathStart > pathEnd) {
         sign = -1;
     } else {
         sign = 1;
     }
     //assign values from nodes to path
     for (var i:int; i<path.length; i++) {
         path[i] = nodes[pathStart+(sign*i)];
     }
 }

This will assign a path based on the start and end points you choose. Use that value with your iTween.MoveTo.

 ChoosePath(2, 5); //move from element 2 in nodes to element 5 in nodes (from nodes[2] to nodes[5])
Comment
Add comment · Show 7 · 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 ATMEthan · Nov 27, 2012 at 07:19 PM 0
Share

Wow this great! Thank you so much! It works perfectly now!

avatar image Screenhog · Nov 27, 2012 at 07:26 PM 0
Share

No problem! Glad I could help!

avatar image ATMEthan · Nov 28, 2012 at 05:38 PM 0
Share

Hey, I have one more question for you. So everything works great like I said before. But I didn't notice this behavior. When the user icon is moving from button x to button y and I click on button z while the user icon is still moving to button y it will teleport to button y position and then move to button z. How can I have it move from where ever it was to button z. Or how can I have it wait to move again after the user icon finishes its path?

avatar image Screenhog · Nov 28, 2012 at 06:04 PM 0
Share

One way: When your icon reaches the destination, check to see if path.length-1 (the last node of the path) is equal to the node that you're currently on. If it's not, call another iTween.$$anonymous$$oveTo to go to the new location.

This will require you to track the node that your icon is occupying, if you're not already doing so.

avatar image ATMEthan · Nov 28, 2012 at 06:37 PM 0
Share

What if the icon is between two nodes? I can't check if it's on a node if it is in between two nodes. Also, what is$$anonymous$$oving bool are you talking about? One that I handle myself or one that iTween has b/c I don't see a is$$anonymous$$oving variable within iTween.

Show more comments

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

11 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

Related Questions

iTween movetopath 1 Answer

How to set iTweenpath dynamically 1 Answer

Combine iTween with physics acceleration 0 Answers

iTween MoveTo 4 Answers

Multiple Cars not working 1 Answer


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