title: Unity3D - How to move objects in a Sine wave independantly?
body: <p>In my game I have targets that spawn and move towards the player in a straight line. I use this code:</p>
  
  <pre><code>transform.LookAt(target.transform);
  transform.position = Vector3.MoveTowards(transform.position, target.transform.position, speed);
  </code></pre>
  
  <p>Which makes the target home in on the player and move towards them.</p>
  
  <p>I decided to try and make them move in a sin wave, so it looks less boring than going in a straight line, and I added a line of code, which now becomes:</p>
  
  <pre><code>transform.LookAt(target.transform);
  transform.position = Vector3.MoveTowards(transform.position, target.transform.position, speed);
  transform.position += transform.right * Mathf.Sin (Time.time * 3f) * 1f;
  </code></pre>
  
  <p>Now this works great, my enemies move left and right as they travel towards the player, except, they all follow the same path at the same time, resulting in a large group of targets moving left and right in a sort of choreographed way.</p>
  
  <p>I believe it is because I use <code>Time.time</code> in the <code>Mathf.Sin</code> piece of code, which results in all the targets using the same value to generate a sine wave.</p>
  
  <p><strong>I've tried</strong> changing to <code>Time.deltaTime</code> and changing the <code>Time.time</code> variable to a <code>Random.Range</code> variable between 2 numbers, but they either don't work, stop my targets from moving, or make them look like they are vibrating. I've also tried using animations as well, but because of my <code>MoveTowards</code> code, this doesn't work either.</p>
  
  <p>So, is there a way to make a <code>GameObject</code> move left and right in a sine wave and move forwards at the same time, but independently so they do not look choreographed? :-)</p>