Challenge with moving platforms

Hi! I have a platform game and a problem with moving (rotating) platforms.

Here is an example that I made of my problem. In this example I made a Capsule with Collider and RigidBody to give the player gravity.

  void Update ()
   {

     // moves the platform
     transform.localEulerAngles = new Vector3(0, 0, rotateTarget);
   
     // moves and changes the direction of platform
     if (direction == false)
     {
       rotateTarget += 50f * Time.deltaTime;
       if (rotateTarget > 30f)
       {
         direction = true;
       }
     }
     else
     {
       rotateTarget -= 50f * Time.deltaTime;
       if (rotateTarget < -30f)
       {
         direction = false;
       }
     }

   }

Here is the video.

I’m not sure how clearly it shows on this video, but the Capsule (in the game player) dives inside the platform. It does this unstable movement up and down. When the platform is moving really fast then the capsule even falls trough the platform.

What I am trying to do is it to move the player with the platform smoothly - if the player is standing on it. It seems as the game updates, the platform has changed its position (by localEulerAngles), but the Capsule with RigidBody is unaware of this and just reacts to new situation. Then if the platform has moved too far above it it falls trough etc.

Any help how this should be done right?

Since you are dealing with physics, you need to use FixedUpdate.
You also need to give the physics object (the moving platform) a rigidbody and mark it as IsKinematic.
Then you need to use MoveRotation (you might be able to use rigidbody.rotation)