Consistent results with mathf.Sin() on respawning gameobjects?

Hi,

I am using Mathf.Sin() to move an enemy, the problem is that when i respawn with SetActive false/true ( i return the gameobject to its original position) the Mahf.sin() function at a given time has a different value (which is to be expected)- thus sometimes making the gameobject start moving downwards and sometimes upwards from it’s starting position, depending the sine function return value at the given moment.

So how can i make that when i activate my gameobject i get the Sin() function always return the same value?

Thanks

when you enable the object store the time

float startTime;

private void OnEnable()
{
    startTIme = Time.time;
}

Then when calling Sin, use the current time minus startTime, then you’ll get the same result when the objects are re-enabled.

float offset = Mathf.Sin(Time.time - startTime);