-
What are you attempting to achieve? (Keep it simple and clear)
I would like to create the ability to look around by just moving the mouse around instead of having to hold the right mouse button. The only difference between this and shift lock is that I do not want to rotate the player when moving the mouse.
-
What is the issue? (Keep it simple and clear - Include screenshots/videos/GIFs if possible)
I do not know how to create this type of mouse look without rotating the player around.
-
What solutions have you tried so far? (Have you searched for solutions through the Roblox Wiki yet?)
I have tried experimenting with things like lockcenter but this is not what I am looking for.
You may then include any further details.
Does anyone know how to make it?
2 Likes
Alright, workspace.LocalCamera has a property called CFrame
The PlayerMouse (which can be obtained by calling :GetMouse() on a LocalPlayer) has a property called Hit, which is a CFrame
Since I dont understand CFrame very well, I cant tell you how to point an object using it, but these two properties can be related to create the effect of pointing a camera without right-click
ps if there’s an easier solution i dont know well then :
Sorry to nit-pick, but it’s workspace.CurrentCamera, not LocalCamera
2 Likes
I have tried experimenting with things like lockcenter but this is not what I am looking for.
It is part of what you are looking for, though. When the mouse has been locked to the center of the screen, you’d use the mouse’s delta to calculate some of the stuff to do with the camera.
Here’s some sample code making something like the camera you described (it’s pretty old so it needs touching up):
local SENSITIVITY = 100
local DISTANCE_Y = 3
local DISTANCE_Z = 12
local BEHAVIOR_LOCK_CENTER = Enum.MouseBehavior.LockCenter
local BEHAVIOR_DEFAULT = Enum.MouseBehavior.Default
local TYPE_MOUSE_MOVEMENT = Enum.UserInputType.MouseMovement
local UserInputService = game:GetService("UserInputService")
local Camera = workspace.CurrentCamera
local HumanoidRootPart = game:GetService("Players").LocalPlayer.Character.HumanoidRootPart
-- Property for changing whether player can move mouse freely or not
local IsLocked = false
-- X and Y values for camera
local X, Y = 0, 0
UserInputService.InputChanged:Connect(function(InputObject)
if InputObject.UserInputType == TYPE_MOUSE_MOVEMENT then
local Delta = InputObject.Delta
X = X + (Delta.Y / SENSITIVITY)
Y = math.clamp(Y + (Delta.Y / SENSITIVITY), -1, 1.5)
end
end)
game:GetService("RunService").RenderStepped:Connect(function()
if IsLocked then
UserInputService.MouseBehavior = BEHAVIOR_LOCK_CENTER
else
UserInputService.MouseBehavior = BEHAVIOR_DEFAULT
end
Camera.CoordinateFrame =
CFrame.new(HumanoidRootPart.Position)
* CFrame.Angles(0, X, 0)
* CFrame.Angles(Y, 0, 0)
* CFrame.new(0, DISTANCE_Y, DISTANCE_Z)
end)
8 Likes
It kind of works, however the way you look around is a bit complicated - is there an easier way?
1 Like
There might be if you make the mathematical stuff a bit more complicated, but in reality this logic is pretty basic.
It’s kind of the bare minimum – you’re positioning the camera at the character’s (HumanoidRootPart’s) position, setting the camera angle (X and Y), and offsetting the camera by the DISTANCE variables so it is from a third-person perspective instead of a first person perspective.
That’s all running every frame. When mouse input happens, the X and Y angles are updated based on the delta (how far the mouse moved) and the sensitivity.
That’s about it, the rest is just some optimisation, variable definition and locking the mouse in the center of the screen.
1 Like
Since roblox has the feature already it isn’t hard to enable it. It just took some time to find it.
-
Find the PlayerModule in PlayerScripts if you already have it there, then find the child “BaseCamera” or PlayerModule → CameraModule → BaseCamera.
-
Require the script in whatever script you’re using as a module script.
-
Jump to line 1070 also called the function “OnMousePanButtonPressed.”
-
Replace its code with this,
function BaseCamera:OnMousePanButtonPressed(input, processed, isEquipped)
self:UpdateMouseBehavior()
self.panBeginLook = self.panBeginLook or self:GetCameraLookVector()
if isEquipped ~= nil then
self.startPos = self.startPos or Vector3.new(input.X, input.Y, 0)
else
self.startPos = self.startPos or input.Position
end
self.lastPos = self.lastPos or self.startPos
self.userPanningTheCamera = true
end
- Now go back to the script where you required the function and invoke it like so (Make sure it’s only called once)
BaseCameraModule:OnMousePanButtonPressed(Mouse, true, true)
-
Whenever the player is done, invoke the function “OnMousePanButtonReleased”
-
Enjoy!!!
1 Like