I think the presented solution for the challenge seems to be way more complicated than would actually be needed.
If you wanted to set the rotation value immediately from when Start()
calls the randomization method (which I think is fairly unnecessary given that it’s updated each frame anyway), one should be able to simply call the already existing RotateHead()
method…
Also, given that all that RotateHead()
depends on is the _currentRotation
, we could simply go and set that value inside RandomStartingRotation()
…
OTOH there would be some easy adjustments to give the spotlights a bit more of a variation than just on which point of the PingPong path they start…
So I did it like this, which also skews the range of the rotation angles and the speed a little bit…
[SerializeField] private float _rotationVariance = 5f;
private void RandomStartingRotation()
{
_currentRotation = Random.Range(-_maxRotation, _maxRotation);
_rotationSpeed += Random.Range(-_rotationVariance, _rotationVariance);
_maxRotation -= Random.Range(0f, _rotationVariance); // note: Don't go beyond the pre-defined max value
}
I just gave that factor a moderate 5f
for a subtle result…