• 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
-1
Question by Rick74 · May 22, 2014 at 09:53 PM · javascriptmovetowardswhile loop

MoveTowards not moving towards! lol.

Can someone do a check on this and see if this works on their end? It seems right to me, and the strange part is that the print statement is firing off every time the while statement loops, yet the object "tractor" will not move!

 function StartTractor ()
 {
     //find the z value by searching through spawner array and comparring y value 
     var findZ:    float;
         
     for (var spawner : Transform in alienSpawnPoints)
     {
         if (spawner.localPosition.y == targetObjectRow)
         {
             findZ = spawner.position.z;
         }
     }
     // sets up the starting position for tractor
     var startPosition     = Vector3(-8.6, targetObjectRow, findZ);
     var endPosition        = Vector3(9.6, targetObjectRow, findZ);
     var step             = 5;
     Instantiate (tractor, startPosition, Quaternion.identity);
     
     while (tractor.transform.position != endPosition)
     {
         tractor.transform.position = Vector3.MoveTowards(tractor.transform.position, endPosition, step * Time.deltaTime);
         print ("in here");
         yield;
     }
     
     Destroy(tractor);
 }

Anyone have any theories why the print fires off, yet the object will not move to it's end goal?

Comment
Add comment · Show 3
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 Rick74 · May 22, 2014 at 10:07 PM 0
Share

I've checked and rechecked. startPosition is (-8.6, 2.1, 5.0) endPosition is ( 9.6, 2.1, 5.0). So it really should be simply travelling a straight line to get from start to end. This blows my brain!

avatar image Jeff-Kesselman · May 22, 2014 at 10:31 PM 0
Share

Why would it move towards lol?

(Hint, "loling" at yourself in your messages is very unprofessional. It reads like a child wrote it. Even if you ARE a child, you don't want to read that way.)

avatar image Rick74 · May 24, 2014 at 02:59 PM 0
Share

Jeff, let's take a step back here and look at this whole picture;

You have just posted in a question, that had already been answered, to insult the person asking the question...

While at the same time, offering no insight regarding the question.

Think about that, and then ask yourself, who comes across as a "child"?

1 Reply

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

Answer by rutter · May 22, 2014 at 10:07 PM

You may want two separate variables: tractor and tractorPrefab.

 tractor = Instantiate(tractorPrefab, startPosition, Quaternion.identity);

Point being, Instantiate returns a reference to the clone. Since you don't save that reference anywhere, you effectively lose track of the newly cloned tractor just as soon as you create it.

Comment
Add comment · Show 1 · 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 Rick74 · May 22, 2014 at 10:14 PM 1
Share

Holy mary mother of god. That worked instantly. I would never have figured that out. $$anonymous$$ake sense though, now that I think about it.

thanks rutter!

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

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

Related Questions

[SOLVED] Coroutine while loop exits before condition met 1 Answer

Unsure why I am getting errors 1 Answer

How to make an object move towards an object at a constant pace, no matter how fast the object is? 0 Answers

Setting Scroll View Width GUILayout 1 Answer

Can someone help me fix my Javascript for Flickering Light? 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