Hi,
I have a 2D bubble game where bubbles spawn from the same position on the left side of the screen then float off to the right in a slight up and down motion. Here is the code attached to the bubble once it has been spawned:
private float amplitude = .4f;
private float speed = 1.5f;
private float tempY;
private float tempX;
private Vector3 tempPos;
void Start ()
{
tempY = transform.position.y;
tempX = transform.position.x;
}
void Update ()
{
tempPos.y = tempY + amplitude * Mathf.Sin (speed * Time.time);
tempPos.x += .05f;
transform.position = tempPos;
}
The first bubble spawns in the right position and moves fine, but each bubble after that spawns slightly higher or lower then the starting position seemingly to match the y position of the first bubble.
I need each bubble to start from the exact same position then float of to the right moving up and down independent from other bubbles.
Please help! Thanks!