Well I tried to rotate normally as if he is in the workspace (Rotating HumanoidRootPart) but it doesn’t seem to change, I wonder if there is any other way to do this
Use Model:SetPrimaryPartCFrame() assuming ur model has a primary part
I recommend you rotate the camera, not the model itself in viewport frames (for performance).
P.s.: the reason for why just rotating the humanoidrootpart doesn’t work, is because ViewportFrames does not calculate physics for the objects parented to it nor take account for welds/motor6ds.
^
The Developer Hub also advises that you rotate the ViewportFrame’s camera, not the model. Updating the models is less performant and more expensive than updating the camera’s CFrame. You can identify a root for the camera to look at and rotate around that part.
How would I go about rotating the camera around the focus?
There are two ways of doing the rotation bit. One way is to increment a rotation value on each .RenderStepped, however I don’t recommend this as it would depend entirely on the fps (frames per second) how fast it will rotate. So if you want consistency with how fast the camera rotates around the focus, you can use my method below where I multiply the time()
with a degrees per second value.
Example:
local Camera = ViewportFrame.Camera
local Focus = ViewportFrame.Model.PrimaryPart
local DegreesPerSecond = 15 -- degrees
local Distance = 5 -- distance away from the focus
RunService.RenderStepped:Connect(function()
Camera.CFrame = CFrame.new(Focus.CFrame.p)
* CFrame.fromOrientation(0, math.rad(time() * DegreesPerSecond), 0)
* CFrame.new(0, 0, Distance)
end)
I’m doing a Character creation and I wanted to move using arrows, But what is above is a loop isn’t it?
edit: i think i understand a bit, thx
What you see above, is not a loop. It’s essentially a function which fires every time a frame is rendered. So in theory, 60 times per second since Roblox caps at 60 frames per second.
Considering you want to be able to rotate the camera using arrows, you can simply just switch that code out with this example and modify it:
local Camera = ViewportFrame.Camera
local Focus = ViewportFrame.Model.PrimaryPart
local DegreesPerSecond = 15 -- degrees
local Distance = 5 -- distance away from the focus
local Time = 0
local Direction = 1 -- Just change this to -1 to rotate the camera towards left, 1 to rotate towards right or 0 to stop
RunService.RenderStepped:Connect(function(dt)
Time = Time + dt * Direction -- dt = deltatime = how much the time has changed since last frame
Camera.CFrame = CFrame.new(Focus.CFrame.p)
* CFrame.fromOrientation(0, math.rad(Time * DegreesPerSecond), 0)
* CFrame.new(0, 0, Distance)
end)
oh sorry sir and thank you (30 char)
Don’t worry. There’s no crime in asking questions!