Rendering the character with a ViewportFrame

You don’t create the new camera. You have a camera inside say workspace maybe centered on a part. you then set the viewportFrame’s camera to the camera centered on the part. Then to render something you can just set the character’s CFrame to the part’s CFrame and shove it in the ViewportFrame.

Here’s my setup for an ItemThumbnail:
image
In blue is the camera brick, and it’s facing the grey BasePart.

image Here’s my workspace setup.

Then I set the ViewportFrame’s camera to the camera in the model.

Then when I want to render something I clone it out of ReplicatedStorage and set the base part’s CFrame to the CFrame of the Base part.

Now on to animations and armor/updates, there are a few things to take note of:

  1. You can only use a LocalScript to edit the model in the ViewportFrame
  2. Make sure when doing things like loading animations or editing the model, you are editing the clone inside the ViewportFrame
  3. For adding Accessories/armor, make sure you either:
    • Set the CFrame of the new accessory to the CFrame of the clone
    • Put the clone (with the accessories) into workspace (Like I said before, workspace has properties that mash the Accessories to the right place)
  4. Make sure you are adding things like accessories and stuff Inside the model in the ViewportFrame

That’s not all of them but those are a few major things to take note of.

Also please share your code if you have further issues.

This is all just my personal preference and other people like it better when they create the camera themselves but I just like a solid foundation.

1 Like

presumably, you can clone the character and update the CFrame of each part when the CFrame of the corresponding parts change, and just use the offset from HumanoidRootPart to move the character within the ViewportFrame?

I’m attempting to replicate what you just told me, and when I run the game the Camera is (destroyed?) or dissapears from the Model that I put it in.

What do you mean by this?

Yes that should happen. The camera will still work in the ViewportFrame but you won’t be able to edit the camera directly.

I believe if you really wanted to you could access the camera by using ViewportFrame.CurrentCamera

1 Like
local offset = HumanoidRootPart.CFrame:toObjectSpace(someOtherPart.CFrame)

You’d then use the offset in your ViewportFrame to position everything relative to the HumanoidRootPart.

1 Like

I presume you’re attempting to do something along the lines of this

if so then I’d recommend using "Dual Render" Scope System

1 Like

Not really, more like the character I linked here.

If you give me some time, I’ll modify my camera system to do that for you!

2 Likes

Sure!

1 Like

Update 6/13/2021:
Rewritten for the latest Luau VM, using better coding style and more efficient practices.

Includes an OFFSET variable to control where the view is positioned relative to the HumanoidRootPart.

Enjoy!

Model File: CharacterViewport.rbxm (4.6 KB)

147 Likes

Does this include updates incase the player has armor added on for example?

1 Like

Oh, my bad.

I’ll go add that and update the OP when done!

Thank you so much, I’ll mark it as a solution for you.

Also one small thing, (although I can fix this), the file you sent does not include the ‘CameraPart’ and ‘Screen’ parts of workspace.

Yeah I forgot to remove that :rofl:

It’s a leftover from the Camera system. I’ve fixed it in this new version that I will send shortly.

Updated the post with a new file

2 Likes

Works, thank you so very much. If you need anything from me, just ask me on the DevForum or twitter, or discord. My respect is eternally given to you.

6 Likes

This works perfectly, but I think there’s a memory leak or something because if I rapidly equip and unequip a tool, my FPS just keeps decimating and decimating. I went from like 80fps to 20 from maybe 10-15 seconds of quick switching

Sounds likely. Something I whipped together quickly a year ago is likely to be subpar.

3 Likes