Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
This question was closed Feb 18, 2019 at 03:35 PM by TheOnlyMike675 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by TheOnlyMike675 · Feb 15, 2019 at 08:53 PM · array of gameobjectstranslation

Translating an Array of Transforms

Hi there! I have been refraining from asking this question for a long time, but I cannot find a similar case online. So here goes.

I have an array of GameObjects and I am interested in translating them all at the same time. To do this, my approach was to loop through the array, toggle a bool in the GO to true, and use the GO's update method to perform the translation. This works when the GO's Update method looks like this:

 void Update()
     {
     
         if(moveThis == true)
         {
             transform.Translate(0,0,0.01f);
         }
     }

This works fine! But when I add additional logic to limit the translation such as this:

 void Update()
     {
     
         if(moveThis == true)
         {
             float x = 0f;
             while (x < 5f)
             {
                 transform.Translate(0,0,0.01f);
                 x += 0.04f;
             }
             moveThis = false;
         }
     }

All of the objects teleport to their destination. I have tried this with lerp, translate, and transform.position += new Vector3(x,y,z), but they all give this teleporting behaviour. Any insight into this would be greatly appreciated! Thanks and have a great day, cheers!

Comment
Add comment · 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 Ymrasu · Feb 15, 2019 at 09:15 PM 0
Share

They still teleport in the second example because even with a while loop in there the Update() method will still complete in one frame. You need to find a way to only move a bit each frame of Update(). One way could be to have each gameobject have a targetDestination field so that you can then lerp from your current position to your target. Then, if you want, ins$$anonymous$$d of sending just a bool saying to move, you can send a destination to move to.

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by bpaynom · Feb 15, 2019 at 09:51 PM

According to your code, what I guess you want to do is

  float x = 0f;
 
 void Update()
      {
      
          if(moveThis == true)
          {
              if (x < 5f)
              {
                  transform.Translate(0,0,0.01f);
                  x += 0.04f;
              }else
                    moveThis = false;
          }
      }
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 TheOnlyMike675 · Feb 15, 2019 at 10:28 PM 0
Share

Wow, thanks so much! That did the trick and I see now why it wasn't working. Thank you :)

Follow this Question

Answers Answers and Comments

100 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 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 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 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 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

Objects Going to 0, 0, 0 Coordinates 3 Answers

How to move an object a fixed distance along one of its axis 1 Answer

Smoothly translating an object down upon Raycast. 1 Answer

How Translation with a fils txt and script I18n ? 0 Answers

onclick on random objects in gamemode and update score 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