Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Totemstem · Apr 07, 2017 at 01:58 AM · vector3listtransform.position

GameObject move to each Vector3s in a list

Hey :)

I'm trying to get a gameObject to move to a start position then move through a list of Vector3s before reaching the end of a path. I've got the start and end positions working well, however, I do not know how to get a gameObject to move through the Vector3 list INORDER. I've tried getting the positionList[i] to convert to a position, however, nothing seems to be working and I'm not sure how to write a sequence to move to each individual point.

This is the code I'm working with;

         if (!startPositionIsSet && middlePossitionListIsSet && endPositionIsSet && Mathf.Approximately(gameObject.transform.position.magnitude, startPoint.magnitude))
         {
             for (int i = 0; i < positionList.Count; i++)
             {
                         gameObject.transform.position = Vector3.Lerp(gameObject.transform.position, positionList[i], 1 / (duration * (Vector3.Distance(gameObject.transform.position, positionList[i]))));
                         Debug.Log("I am at " + transform.position + " Moving to position " + positionList[i]);
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
0
Best Answer

Answer by Cuttlas-U · Apr 07, 2017 at 09:03 AM

hi;

u should use Coroutine for this I write the code for u ;

just put the vector3 in the inspector and set the object that u want to move between positions;

     public Vector3[] positions;
     public Transform ObjectToMove;
     public float MoveSpeed = 8;
     Coroutine MoveIE;
 
     void Start()
     {
         StartCoroutine(moveObject());
 
     }
 
     IEnumerator moveObject()
     {
         for (int i = 0; i < positions.Length; i++)
         {
             MoveIE = StartCoroutine(Moving(i));
             yield return MoveIE;
         }
     }
 
     IEnumerator Moving(int currentPosition)
     {
         while (ObjectToMove.transform.position != positions[currentPosition])
         {
             ObjectToMove.transform.position = Vector3.MoveTowards(ObjectToMove.transform.position, positions[currentPosition] , MoveSpeed * Time.deltaTime);
             yield return null;
         }
  
     }



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 Totemstem · Apr 14, 2017 at 08:39 AM 0
Share

Thank you for this I really appreciate it :)

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

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

Related Questions

Helicopter Move Local Position,Local Position 1 Answer

Are I stupid? Vector3 1 Answer

Reversing movement directions 1 Answer

List.Contains not working as intended 0 Answers

Trying to transform my character's local position on a GetKey. 0 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