Get the character to face the correct direction while flying

I’ve made a script to let the player fly around like a superhero, and so far everything works smoothly, except that once I start flying, the orientation of the character is locked. There’s a video of the issue below.
robloxapp-20200911-1436031.wmv (2.3 MB)
I tried fixing this by manipulating the CFrame or Orientation of the HumanoidRootPart based on that of the camera, but the issue is I cannot do that without setting the position of the HRPart. So I tried, for example;
HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.Position, HumanoidRootPart.Position + Camera.CFrame.LookVector)
(That’s just a representation of what I did, I had to retrieve the camera’s LookVector from the client, then I’m applying the change on the server.)

The issue with this method is that the HRPart’s CFrame gets repeatedly set to itself, which apparently prevents movement. (There’s a rough example of this below.)
robloxapp-20200911-1439158.wmv (2.3 MB)

So what I need is a way to change the Y orientation of the HumanoidRootPart based on the CFrame of the camera, without changing the position, since doing so screws up the entire flight (which, by the way, is done via BodyVelocity).

Any ideas? I’m not sure why all the things I tried aren’t working, and Google was no help.
Thanks in advance!

you could always change the rotation of the HRP by doing this:

HumanoidRootPart.Rotation = Vector3.new(HumanoidRootPart.Orientation.X, 10, HumanoidRootPart.Orientation.Z)

This didn’t fix it. For some reason the HRPart still keeps snapping back into the previous position when I try to change the orientation or the CFrame. It probably has something to do with the fact that I’m using BodyVelocity…?

Okay, actually I fixed this. I discovered that you can assign a CFrame to BodyGyro instead of just having it default to 0,0,0 all the time. This is what I didn’t know.
I’ll explain what I did for prosperity :yum:

Essentially, I put a BodyGyro (with a high [but NOT infinite] P factor) into the HumanoidRootPart along with the BodyVelocity. Then I used CFrame:ToEulerAnglesXYZ() to get the orientation of the camera, and then assigned it to the HRPart using CFrame.Angles.
There’s more to what I did simply for aesthetic reasons, but I won’t go into those. Here’s an example script (don’t copy and paste, that won’t work. It’s just a representation/summary, you need both local and server scripts for this):

while wait() do
    local hrp = player.Character.HumanoidRootPart
    local bv  = hrp.BodyVelocity
    local bg = hrp.BodyGyro

    if (flying) then
        local X,Y,Z = camera.CFrame:ToEulerAnglesXYZ() -- get the camera's orientation
        bg.CFrame = CFrame.Anges(X,Y,Z) -- set the target orientation of the BodyGyro to that of the camera
        bg.MaxTorque = Vector3.new(0,400000,0) -- give the BodyGyro the power it needs to correctly rotate the HumanoidRootPart to match the camera
    else
        bg.MaxTorque = Vector3.new(0,0,0) -- if not flying, prevent the BodyGyro from having any power over the rotation.
    end
end

There’s a lot of other stuff I did, the block above is just a description of essentially how I did the BodyGyro.