So today I will show you how to make viewportframe object face mouse on screen
Start off by inserting a part on workspace and set position to 0,0,0
Create another part, and make the front face face the part we created before.
Let’s call our part which will be put in the viewportframe Bose, and the white part Gerald
Gerald will be the part where the camera will share the cframe with
Clone the camera, and name it Newcam
Go to command bar, and type in workspace.Newcam.CFrame=workspace.Gerald.CFrame
Insert the newcam into the viewportframe, and bose into it as well
Set the viewportframe CurrentCamera to be newcam
You should now be able to see bose
Delete Gerald
And enter this script
while wait() do local v = script.Parent.ViewportFrame.Part local x,y,z = CFrame.new(Vector3.new(9,0,0),Vector3.new(game.Players.LocalPlayer:GetMouse().X,-game.Players.LocalPlayer:GetMouse().Y,1000)):ToOrientation() game:GetService("TweenService"):Create(v,TweenInfo.new(.4,Enum.EasingStyle.Quint),{Orientation = Vector3.new(x*25,-(100-((y*125)/5)),z)}):Play() end
Let me break down the code for you.
So basically, the math is pretty simple
What it is doing is it’s taking the mouse screen pixel position, and dividing it by the screen pixel size, which allows this to work on all screen sizes.
It uses a very basic cframe method that lets a part face a position with two Vector3s.
A visualisation is here
The plane mouse is on is offset through a Z value, which can control how much bose is facing the camera
(Also I made a mistake in the visualisation, it’s bose not gerald)
The tween just basically makes it look better.
Here is the playtest