Question on implementing a "radar" rotating object.

Consider what is essentially a radar.

I want the “radar” to rotate at a certain speed, say 20 degrees per second. No problem with how to do that.

But…I want to scan at fixed intervals, such as every one degree.

Any suggestions on how to structure this?

I’m early in the process of thinking about how to do this and searching forums for people doing similar things.

Thanks!

My early thoughts on how to do this:
The rotation is linked to Time.deltaTime, which will be different on different systems…how fast they run things. At each Time.deltaTime, I can do the rotation, and then calculate if at least one degree of rotation is past, and if so, do the scan. On a slow system, if the Update is happening at less than 20 degrees/second, then I have to adjust to some slower scan interval, such as every 2 degrees.

Shouldn’t matter. Your want your radar to rotate at the same real world speed no matter what the framerate is. That’s the point of using Time.deltaTime in the first place.

Nah, if necessary, do multiple scans in a single frame. Something like this should work:

[SerializeField]
Vector3 rotationAxis;

[SerializeField]
float rotationSpeed; // Degrees per second

[SerializeField]
float scanInterval; // Degrees per scan

float rotationAccumulator = 0;

// This variable is just in case your scans need to know what direction to scan in.
float currentRotation = 0;

void Start() {
  rotationAxis.Normalize();
}

void Update() {
  float degreesToRotate = rotationSpeed * Time.deltaTime;
  transform.Rotate(rotationAxis * degreesToRotate);

  rotationAccumulator += degreesToRotate;
  while (rotationAccumulator >= scanInterval) {
    rotationAccumulator -= scanInterval;

    // increment the scanning direction
    currentRotation += scanInterval;

    // perform the actual scan (with a certain rotation)
    DoAScan(currentRotation);
  }
}

void DoAScan(float atThisRotation) {
  // Whatever code you need to perform a scan.
}

This helped a lot. Thank you!