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 Fred_Vicentin · Apr 01, 2014 at 06:36 PM · itweenpath

iTween path using self object as path0

Im trying to move an instantiated prefab using itween and I want that the first path is itself, for example, move it to another point using iTween.

I tryied many ways, my last try is I used the object as Vector3,

Take a look at my code:

 public Transform[] path;

 void Start()
     {

         Vector3 position1 = new Vector3(transform.position.x, transform.position.y, transform.position.z);
         path[0] = position1;
     }
 
 void OnMouseDown ()
     {
         if(transform.gameObject.tag == "Player")
         {
             iTween.MoveTo(gameObject, iTween.Hash("path", path,"axis", "-x", "movetopath", false,  "orienttopath", true,"speed", 100));            
 
 
         }
     }
 }

The error was that:

error CS0029: Cannot implicitly convert type UnityEngine.Vector3' to UnityEngine.Transform'

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

2 Replies

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

Answer by robertbu · Apr 01, 2014 at 06:56 PM

You can do it this way:

 void Start() {
     var t = new GameObject().transform;
     t.position = transform.position;
     path[0] = t;
 }

Note I'm assuming that you are creating a path in the Inspector. If the size of 'path' is 0 when Start() is executed, you will get an out of bounds error.

Comment
Add comment · Show 3 · 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 Fred_Vicentin · Apr 01, 2014 at 07:03 PM 0
Share

It don't appeared on the Inspector, don't worked, I'm Instantiating the object so I cant only drag the path to it

avatar image robertbu · Apr 01, 2014 at 08:50 PM 0
Share

This is not the whole script. This is the replacement for your Start() function in your script above.

avatar image Fred_Vicentin · Apr 01, 2014 at 09:31 PM 0
Share

I just replaced the Start() but it dont worked

avatar image
0

Answer by Fred_Vicentin · Apr 01, 2014 at 08:41 PM

I done by myself:

Its working, thanks for the help

     public Transform fruta;
     public Transform mao;
     public Transform[] path;
     
     void Start()
     {
         fruta = gameObject.transform;
         mao = GameObject.Find("Mao").transform;        
         path[0] = fruta;
         path[1] = mao;
     }
Comment
Add comment · Show 3 · 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 robertbu · Apr 01, 2014 at 08:53 PM 0
Share

This will compile, but will it run right? Transforms are by reference, so you will be changing the position of 'path[0]' each frame effectively shortening the path.

avatar image Fred_Vicentin · Apr 01, 2014 at 09:30 PM 0
Share

Yes, it worked right for me, I used with iTween and worked as I want to

avatar image robertbu · Apr 02, 2014 at 12:47 AM 0
Share

Your solution here has a potential problem based on my belief at how iTween functions. It re-evaluated the path each frame. You are putting the transform of your game object in the path. The result is that the path is changing each frame...shortening as the position of your game object moves closer to the goal. I believe this means two things. First, if you were to clock your object across the path, you would find the movement is not linear. This may be hidden in part by whatever the default tween is for iTween movement. Second, you could not move back across the same path because you lose the starting point.

There is one other strange/potential problem with what you've done here. 'path' has to have its length set to 2 or more in the Inspector. Typically if the programmer was not going to set the path in the Inspector, he would make the variable private and initialize 'path' in start:

 path = new Transform[2]; 

Actually given how you are using 'path', making 'path' and array of Vector3s might be better.

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

20 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 avatar image

Related Questions

ITween orienttopath x-y-z? 1 Answer

iTween makes a weird start on the path 1 Answer

How do you create random paths in iTween? 0 Answers

how to cancel iTween Catmull-Rom path 1 Answer

iTween even velocity 9 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