Search Unity

wave animation

Discussion in '2D' started by z3, Aug 21, 2016.

  1. z3

    z3

    Joined:
    Jun 3, 2016
    Posts:
    34
    can anyone tell me how to smoothy move a sprite to the left and then say copy and keep looping it in from the right to make stuff like waves?


     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    I'd use a simple script. In the Update event, just do a transform.Translate by some amount proportional to Time.deltaTime, and then check whether it's gone off the screen to the left — if so, move it back to the right.

    I'd use probably use two (or more) of these, but I guess you could do it with one big one, and just move it as soon as it's shifted by a full wavelength.

    Another option, come to think of it, would be instead of using transform.Translate, just set the position based on Mathf.Repeat(Time.deltaTime, k). This would shift the sprite for a while, and then jump back and do it again, as time proceeds (the constant k here determines the time scale of this process). So, multiply that by an appropriate value to get a position that shifts aside by one wavelength and repeats, and that would give you your apparently-continuous waves, too.