How would I make the player's character fully follow the camera's orientation using BodyGyro?

I got the main hang of the system, especially the left to right axis:
https://gyazo.com/f4f84c7b2e98e9056ceffe78a6a9906c

It uses renderstepped on the client side and matches a bodygyro CFrame located in the HumanoidRootPart to the cameras CFrame. Below is the script that achieves this:

However, it’s not as accurate when it comes to up and down and does a fraction of the cameras orientation. Does anyone know why this occurs? I believe it is due to humanoids automatically standing up when falling. But please correct me if I am wrong.

5 Likes

It would help us to be able to help you if you could give us a script top look at as this is scripting support.

4 Likes

I will add that in now, completely forgot about it thank you :smiley:

You want the lookVector from the camera cframe position to the player’s rootpart.

This will work for any rotation or angle.

2 Likes

As @ShadowOfCrimson said, a better way to achieve this is buy using the camera’s CFrame’s lookVector, the lookVector is the direction of looking of that specific cframe. This is the second paramater of CFrame.new(pos, look). If we set the “look” paramater of the cframe of part A, to the position of part B, part A would be facing part B.

We won’t actually be setting the character’s humanoidrootpart to the camera’s lookvector (Camera.CFrame.lookVector), since the lookVector is a unit vector, which means its 1 stud long, so if we do that the player would be looking backwards, because he’s trying to look at the camera’s lookvector which is facing his direction, but its too short so its behind him.
So what we have to do is make it longer, by multiplying it by a scalar (a number).

character:SetPrimaryPartCFrame(CFrame.new(character.HumanoidRootPart.Position, camera.lookVector * 10))
--we set the hrp to the same position and facing where the camera is facing, 10 was just an example, what we  multiply by doesnt really matter since how long it is doesn't change the direction

And also your script wasn’t working because of the way you were using that targetPos variable, you were saving the CFrame property of hrp (rootPart.CFrame) to that var, and saving a property inside of a variable doesn’t save a reference to that property it saves the value that property was set to, so the rootpart’s cframe won’t change.

Another small suggestion is using :BindToRenderStep() instead of the RenderStepped event, they do the same thing, but with the :BindToRenderStep() method we can control the priority of the rendering, so in our case we want our thing to have the priority of the camera, makes sense.
Look up :BindToRenderStep() it’ really useful.

local function UpdateCFrame(char)
   char:SetPrimaryPartCFrame(CFrame.new(char.HumanoidRooPart.Position, camera.CFrame.lookVector * 10))

end

RunService:BindToRenderStep("CFrame Update", Enum.RenderPriority.Camera.Value, UpdateCFrame)

Sorry if this post is messy or not well explained I am answering from my phone xd. I’m not even sure if this would work

4 Likes

I will see if this would work, thank you!

1 Like