Spawn Objects In Different Locations With Mathf.Sin()

I have a series of spawn points that is randomly spawning my enemy objects.

					var clone1 = Instantiate(shipObjects[Random.Range(0, 0)], 
					shipSpawnPoints[Random.Range(0, shipSpawnPoints.Length)].transform.position, transform.rotation);

Im using the Mathf.Sin() to make the objects move in a wave motion. The issue is that is interfering with my instantiate array.

count -= Time.deltaTime / waveTimer;
   		 	var offset = Mathf.Sin(Time.time * directionSpeed + timingOffset) * .3f;
   		 	transform.position = new Vector3(offset, .55f, count);

How do I bring these together so the objects will spawn on from the random spawn points and keep the wave effect?

Save the start position for each of them, then set the position like so :

transform.position = startPosition + new Vector3(offset, .55f, count);

That way, the result of the sinus is only an offset. I guess that’s what you had in mind, considering the variable name.

I’m trying to understand both what you want and what your code is doing or not doing. I took the snippets of code you have above and dropped them into Unity. I had to make up values for several of the variables because you did not post the code. So my result is:

public class Spawner : MonoBehaviour {

	Vector3 startPosition ;
	float directionSpeed = 11.0f;
	float timingOffset = 1.0f;	
	float waveTimer = 0.5f;
	float zPos = 0.0f;
    void Awake() {  
       startPosition =;
	void Update() {  
		InvokeRepeating("Creator", 0.01f, 0.5f);
	void Creator()
        zPos -= Time.deltaTime / waveTimer;
           float offset = Mathf.Sin(Time.time * directionSpeed + timingOffset) * 3.0f;
         //transform.position = startPosition + new Vector3(offset, .55f, zPos);
			Vector3 v3Pos = startPosition + new Vector3(offset, .55f, zPos);
			GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
			go.transform.position = v3Pos;

As you can see in the code, I’m creating a cube at each of the points you set the transform for the game object this script is attached to. When I run this script I get:

This is looking down from above. So with these values, the game object that has this script attached is walking the path in the image. Is this what you are looking for? This looks like what you described you wanted in the original question. If its not what you are looking for, what should happen? If is what you are looking for, what is happening instead?

Final answer:

public GameObject[]				shipSpawnPoints;

Vector3 startPosition;

	void Awake()
		shipSpawnPoints = GameObject.FindGameObjectsWithTag("SpawnPoint");
		startPosition = shipSpawnPoints[Random.Range(3,7)].transform.position;

	void Update() 
		transform.rotation = Quaternion.LookRotation(rigidbody.velocity);
		transform.rigidbody.AddForce(xVect, yVect, zVect);
	 		zPos -= Time.deltaTime / waveTimer;
   		  	float offset = Mathf.Sin(Time.time * directionSpeed + timingOffset) * .3f;
			transform.position = startPosition + new Vector3(offset,0, zPos);

Works beautifully!