Trying to get swords to rotate properly in ViewportFrame

Rotating the sword so that it faces vertically in a ViewportFrame is fine, but don’t rotate the actual sword in the ViewportFrame. Apply rotations towards the camera instead.

Whenever you update the contents of a ViewportFrame, it forces it to re-render. Changing the camera is less performance heavy than changing the rotation of parts. This is not only a recommendation by the Developer Hub but it also lines up with the Gui engine improvements where Guis are cached until they’re changed in any way, improving performance.

That’s to say: feel free to continue to rotate swords so they face vertically, but don’t change the rotation of the swords. Focus on making the swords stand vertically and the camera rotating around the center point where the sword is located.

There are some other recommendations that can be offered here. I notice that you use the parent argument while instancing a new ViewportFrame: don’t. Next is that I think you’re using both while loops and RenderStepped incorrectly: consider RunService.BindToRenderStep. Camera updates are fine in RenderStepped but just be wary about the fact that running something in RenderStepped can block frames from rendering and code from running, content depending.

2 Likes