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 bobdiya · Aug 21, 2016 at 04:13 PM · 2dmovementparticlesystemstretching

How to implement a stretched movement?

I want to implement a stretched movement of a set of objects in a well. Let us call the object a fish.

  • Here is screenshot of the movement alt text

  • Here is the link to the video of the movement. This video clearly shows the exact effect that I want to implement.

My approach (For a particular fish)

  public GameObject[] fish = new GameObject[6];
  1. Set the from and destination for the fish to move

  2. Move the fish

       StartCoroutine (DoEntireFishStride (startPosition, target));
    
    
  3. Move each of the Fish parts

      IEnumerator DoEntireFishStride(Vector3 from, Vector3 toWhere){
             // fish[0] head
             StartCoroutine(DoTheStride(fish[0], from, toWhere));
             yield return new WaitForSeconds(0.15f);
             StartCoroutine(DoTheStride(fish[1], from, toWhere));
             yield return new WaitForSeconds(0.15f);
             StartCoroutine(DoTheStride(fish[2], from, toWhere));
             yield return new WaitForSeconds(0.15f);
             StartCoroutine(DoTheStride(fish[3], from, toWhere));
             yield return new WaitForSeconds(0.15f);
             StartCoroutine(DoTheStride(fish[4], from, toWhere));
             yield return new WaitForSeconds(0.15f);
             StartCoroutine(DoTheStride(fish[5], from, toWhere));
    
             yield return new WaitForSeconds(3.5f);
     }
    
         // Moves a single part of the fish
     IEnumerator DoTheStride(GameObject movObj, Vector3 from, Vector3 toWhere){
         movObj.transform.position = from;
    
         float dist = Vector3.Distance(toWhere, movObj.transform.position);
         int totalSteps = 3;
         float step = dist/(float)totalSteps;  // Take 4 steps to go to the dest
         int smallSteps = 25;
         float smallStep = step/(float)smallSteps;
    
         while(totalSteps > 0){
             yield return new WaitForSeconds(0.8f);
             while (smallSteps > 0) {
                 yield return new WaitForSeconds(0.01f);
                 movObj.transform.position = Vector3.MoveTowards(movObj.transform.position, toWhere, smallStep);
                 smallSteps -= 1;
             }
             totalSteps -= 1;
             smallSteps = 25;
         }
     }
    
    
  4. Goto Step 1. Continue until we want the movement


Note: I've implemented the above described approach and it is giving a decent effect. But not the entire effect as in the video

Questions

  1. Is there something in Unity that I can use out of the box to get this movement? (Particle system? etc)

  2. It feels like the approach that I have described is very fragile ( it is too much dependent on Waits), so is there anything that I can do to better my approach?

fishmovement.png (109.4 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Sprites moving (shaking) during animation while they should not 1 Answer

2D moving Script 1 Answer

2D Top Down, Enemy facing player slow rotation issue. Vector gets messed up after collision. 3 Answers

Constraning an object's forces to only two directions in 2D (or infinite friction?) 0 Answers

How do I render Particlesystems in front of 2D sprites? 2 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