Auto hovering

  if (distance == 30)
  {
    while (distance == 30)
    {
      if (throttle_channel > 1350)
      {
        throttle_channel -= 1;
      }
      esc3.writeMicroseconds(throttle_channel);
    }
  }

This will have the effect of setting the throttle to 1350 and ignoring all other inputs if the distance is ever >30.

it is roughly equivalent to:

  if (distance == 30) {
    esc3.writeMicroseconds(1350);
    while (true) {/*Do Nothing*/}
  }

May I know how the code(or the function i have to use) will be if i use PID ?
Im finding a trouble with the code
im using -- GY - 521 (MPU6050)
-- Ultrasonic sensor HC-SR04
-- arduino uno

zaidalfityan:
May I know how the code (or the function i have to use) will be if i use PID ?
Im finding a trouble with the code

The PID library has three 'float' values: Input, Setpoint, and Output. Input and Setpoint have to be in the same units. The Output is just a number to control the system.
In your case Input and Setpoint are a measure of distance and Output is the throttle value. You will need to set the Output limits to 1000 and 2000 to get values for an ESC. Set Setpoint to 30. Measure the distance and use that for Input. Call the PID and use the Output for your throttle.

You will need to tune the PID. Look for PID Tuning instructions online.