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
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];
Set the
from
anddestination
for the fish to moveMove the fish
StartCoroutine (DoEntireFishStride (startPosition, target));
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; } }
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
Is there something in Unity that I can use out of the box to get this movement? (Particle system? etc)
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?
Your answer

Follow this Question
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