I’ve been using Unity for a little bit but haven’t released anything yet. I do have some knowledge of both 3D and 2D now, but I have one thing that I’m completely stuck on. Keep in mind I’m also a 16-year-old sophomore in high school.

I don’t want to release too much, but I’m essentially making a one-button rhythm game about this sine wave that moves along the screen, and you have to press when it crosses the middle when there’s also a dot. I’ll probably add other simple mechanics later (becoming faster/slower, holds, etc.) but first I’m getting the main sine and dots. I’ve successfully made the sine but I CANNOT get the dots to align to the middle. I’ve even done it in a Desmos graphing calculator, but not in Unity.
The dots come from the right and only move on the x axis if that helps.

If you have any questions, I can explain. I may also be able to show some examples if needed. Thank you to anyone that responds (and Happy Holidays)!

Dot Movement Script:

``````void Start()
{
sw = GameObject.Find("Sine Wave").GetComponent<SineWave>();
timer = 0;
}

private void Update()
{
if (timer < (4 * Mathf.PI))
{
timer = timer + Time.deltaTime;
}
else
{
timer = 0;
}

if (transform.position.x < -12)
{
Destroy(gameObject);
}
}

void FixedUpdate()
{
Vector2 pos = transform.position;

pos.x = pos.x - (sw.movementSpeed * Time.deltaTime / (2 * Mathf.PI));

transform.position = pos;
}
``````

}

Sine Wave Script:

``````void Start()
{
myLineRenderer = GetComponent<LineRenderer>();
}

void Draw()
{
float xStart = xLimits.x;
float Tau = 2 * Mathf.PI;
float xFinish = xLimits.y;

myLineRenderer.positionCount = points;
for (int currentPoint = 0; currentPoint < points; currentPoint++)
{
float progress = (float)currentPoint / (points - 1);
float x = Mathf.Lerp(xStart, xFinish, progress);
float y = amplitude * Mathf.Sin((Tau * frequency * x) + (Time.timeSinceLevelLoad * (movementSpeed / Mathf.PI)));
myLineRenderer.SetPosition(currentPoint, new Vector3(x, y, 0));
}
}

void Update()
{
Draw();
}
``````

}

The issue is in your Draw script. You perform this calculation:

``````Mathf.Sin((Tau * frequency * x) + (Time.timeSinceLevelLoad * (movementSpeed / Mathf.PI)));
``````

However, in this calculation, you are adding a number on top of your sine wave, which is going to move it off the x axis. What you want to be doing is

``````float y = amplitude * Mathf.Sin(Tau * frequency * x + (Time.timeSinceLevelLoad * (movementSpeed / Mathf.PI)));
``````

Which offsets your x by the factor, instead of offsetting the y by the factor.