Moving sine wave curve 2D

Hi everyone,

I am a Unity beginner. I would like to have a moving sine wave curve in my game which has to be followed with a ring (hot wire game). So far, I just found informations concerning game objects which should move in a sine wave manner. Do I have to do this with the lineRenderer? I would be very happy for some help. Thank you very much.

The line renderer is used to draw single pixel-wide lines on the screen.
If you want to move an object, you will need to change it’s position (object.transform.position). You probably want to override the moving objects Update() function (called every frame), and inside there compute the new position and assign it e.g. this.transform.position = new Vector3(t, Mathf.Sin(t),0); //where t is the "angle"

Edit/Update:
This version is flexible to show you what I did, and how I did it. You will need to add this script to a game object for the script to start and update:

using UnityEngine;
using System.Collections;

public class FunctionObjectPlotter : MonoBehaviour {

    public GameObject plotPointObject;
    public int numberOfPoints= 100;
    public float animSpeed =1.0f;
    public float scaleInputRange = 2*Mathf.PI; // scale number from [0 to 99] to [0 to 2Pi]
    public float scaleResult = 10.0f;
    public bool animate = true;

    GameObject[] plotPoints;

	// Use this for initialization
	void Start () {

        if (plotPointObject == null) //if user did not fill in a game object to use for the plot points
            plotPointObject = GameObject.CreatePrimitive(PrimitiveType.Sphere); //create a sphere

        plotPoints = new GameObject[numberOfPoints]; //creat an array of 100 points.

        for (int i = 0; i < numberOfPoints; i++)
        {
            plotPoints *= (GameObject)GameObject.Instantiate(plotPointObject, new Vector3(i - (numberOfPoints/2), 0, 0), Quaternion.identity); //this specifies what object to create, where to place it and how to orient it*

}
//we now have an array of 100 points- your should see them in the hierarchy when you hit play
plotPointObject.SetActive(false); //hide the original

  • }*

// Update is called once per frame
void Update()
{
for (int i = 0; i < numberOfPoints; i++)
{
float functionXvalue = i * scaleInputRange / numberOfPoints; // scale number from [0 to 99] to [0 to 2Pi]
if (animate)
{
functionXvalue += Time.time * animSpeed;
}
plotPoints_.transform.position = new Vector3(i - (numberOfPoints/2), ComputeFunction(functionXvalue) * scaleResult, 0);_
}
* }*
float ComputeFunction(float x)
{
return Mathf.Sin(x);
}
}

I would be very happy to get some help… I worked the whole day on that problem… without any success=(

When I change the scale of the spheres there is a gap between (see screenshot). How can I adapt the code that even if the spheres are small that the are all aligned?

Thank you for your help!

[65543-screenshotrtfd.zip|65543]