I want to write code that will always make the player's camera look at the position where the player's mouse is at any given time. However, I am a bit stuck as to how to do this.
So on the ROBLOX Wiki it says that you can no longer change the Camera's Focus, so now I'm at a lost as to how to tell the Camera where to look.
To start off, I'll introduce a body force that you may or may not have heard of, BodyGyro. Put simply, a BodyGyro will influence the rotation of whatever BasePart it is parented to. With this said, we'll be using this as our main means for making our character face his or her camera.
I should also mention that we can set the CFrame of our character without he or she dying, this is because it doesn't break joints or reset welds or anything of that sort. So that's where we'll be putting our BodyGyro.
local player, bG = game.Players.LocalPlayer, Instance.new("BodyGyro", game.Players.LocalPlayer.Character.Torso)
This will make the BodyGyro and put it in our characters torso, but we haven't defined the MaxTorque of the gyro. We need to set it to something that won't cause our character to do back and front flips out of control. For this, we'll set it to 10,000 on the Y-Axis.
bG.MaxTorque = Vector3.new(0, 10000, 0)
So, now we've set up the BodyGyro. Next we just need to set up a loop to set the CFrame of the gyro to face the mouse. For this, we'll get the mouse, and set the CFrame.
while wait() do bG.CFrame = CFrame.new(player.Character.Torso.Position, player:GetMouse().Hit.p) end
Hope this helped.
Also, I apologize if I have a flawed understanding and have given poor or inaccurate explainations.
Do you mean that the player will look in the direction of the cursor? If so, you have to change the player's torso's CFrame to face in the direction that you are pointing. The variables are so the none of the lines are too long. You can remove them if you want.
local lp=game:GetService("Players").LocalPlayer local m =lp:GetMouse'' local t =lp.Character.Torso while wait() do t.CFrame=CFrame.new(t.Position,Vector3.new(m.Hit.p.X,t.Position.Y,m.Hit.p.Z)) end