Remove Right Click Turning

Ok I downloaded and imported the file to starterGui but still nothing

Do you have that pervious LocalScript running?
Try disabling it

That ImageButton should take up the entire screen and prevent players from using right click to drag the camera around.

1 Like

I don’t think that might be possible at this point since we shouldn’t anchor the head of the player because we won’t be able to move or even spawn. This is doing because we attached a camera to head and we are playing animation on the character. This may maybe work if you delete the animation of the character. I hope this helps. :herb:

Edit: yeah try to delete the animation from the character.

1 Like

Thanks for all the help! Honestly the bounce is so small it’s hard to even notice.

1 Like

If you’re trying to remove the bounce using @ArticGamerTV’s code, try replacing

game.Players.LocalPlayer.Character.Head.Position

with

game.Players.LocalPlayer.Character.HumanoidRootPart.Position+Vector3.new(0,3,0)
1 Like

@ArticGamerTV (cc @TheYelloMacaroni) This is an ugly hack, stop using it. You’re going to encounter weird artifacts and this isn’t the proper way to do it anyway. If you want to remove right click turning, just prevent the right mouse button from passing input.

local ContextActionService = game:GetService("ContextActionService")

ContextActionService:BindActionAtPriority("NoRMBDrag", function()
    return Enum.ContextActionResult.Sink
end, false, Enum.ContextActionPriority.High.Value, Enum.UserInputType.MouseButton2)

Consequently, in order to make any right mouse functions work, you must use the same method of ContextActionService bindings but use a higher priority value so it won’t be sunk by the above (Enum.ContextActionPriority.High.Value + NUM). IIRC Guis won’t be affected.

22 Likes

Dude thank you so much. Actually Worked

1 Like

It worked but when I try to move backward it just starts spinning around my player and going crazy. The camera position and angle affects the way the player moves so i was wondering if there is a way around that

Cue: my suggestion, which was evidently skipped over. This is why I said you should use my solution. Now because you’re using the RenderStepped camera lock, you’re running into additional problems and needing extra code. It’s more work than it’s worth.

You can either keep trying to apply hacks and workarounds which may ruin the player experience or require more maintenance from your end, or you can just remove all the turning-based work you’ve done until now from this thread and just use my solution. Less lines, cleaner removal supported natively by the API and generally a better solution.

3 Likes

One of the best ways around this in my opinion
and as @colbert2677 mentioned is using the ContextActionService. it will ultimately help you in the long run, using and manipulating the camera will not as much(unless you intend to create a whole camera controller). Tl;dr there is no clearcut and keep in mind, stable way as of now to disable right click for rotating the camera ( I’m pretty sure) using the current Camera Controller. Of course you could fork the player scripts and manipulate the camera, but this comes with some what of a “consequence”. Firstly the forked scripts and methods that you make will not update, to adapt with the newer/future versions of the camera and base camera controllers where as native player scripts will. And they could be prone to breaking especially if you intend to extensively customize the camera. The context action service might change some time in the future, but I would say it is a lot more stable and reliable then “overwriting” the camera to stop right mouse click movement overall, as it can “disable” the input as an action which can be less expensive and more beneficial in some aspects. Just my thoughts and recomendations, either way good luck on your project!

Honestly even i’m getting a little confused on my own topic, here’s what I’m trying to achieve.

D and A just move you, don’t turn you, your mouse is what moves you around.

Well, the rotating thing with the character is easy to change, as there is a built in property for it. Humanoid.AutoRotate can be used to toggle whether the humanoid rotates when they move (left or right). I am not sure what you mean by the mouse just moves you around, are you saying you want MouseButton1 to move the camera instead of MouseButton2?

Code Example
local player = game.Players.LocalPlayer
local Humanoid = player.Character:WaitForChild("Humanoid")
Humanoid.AutoRotate = false

Sounds like your camera mode is set to “Follow” try classic instead.

Read the post they’re replying to for context. It doesn’t have to do with the camera mode; it has to do with the code that was posted. The code in question sets the Camera CFrame to a certain point through a listener on RenderStepped.

I mean that just moving your mouse, not pressing anything rotates you around.

Okay so I put
local player = game.Players.LocalPlayer
local Humanoid = player.Character:WaitForChild(“Humanoid”)
Humanoid.AutoRotate = false

in a LcalScript in StarterGui but i want it so that when you move your mouse across the screen without clicking any buttons you turn that direction.

I made a Barebones , simple camera controller that i edited from code i found on the wiki that you can use:

Source: UserInputService | Documentation - Roblox Creator Hub

CameraController.lua (4.4 KB)

--------------------------------------------------------------------------------------------------------Varibles
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
 
local camera = game.Workspace.CurrentCamera
local players = game:GetService("Players")
local player = players.LocalPlayer
local Character = player.CharacterAdded:Wait()
local AnchoredObject = Character:WaitForChild("UpperTorso") or Character:WaitForChild("Torso") 

local playerPosition = AnchoredObject.Position
local default_CameraPosition = AnchoredObject.Position + Vector3.new(0,1.5,0)
local default_CameraRotation = Vector2.new(0,math.rad(-60))
local default_CameraZoom = 25
 
local cameraPosition = default_CameraPosition
local cameraRotation = default_CameraRotation
local cameraZoom = default_CameraZoom
 
local cameraRotationBounds = {math.rad(-81),math.rad(20)}
local cameraZoomBounds = nil --{10,200}
local touchDragSpeed = 0.15
local cameraSpeed = 0.1
local cameraRotateSpeed = 10
local cameraMouseRotateSpeed = 0.25
local cameraTouchRotateSpeed = 10


---------------------------------------------------------------------------------------------------------- 



local function SetCameraMode() ---Set the camera mode
camera.CameraType = "Scriptable"
camera.FieldOfView = 80
camera.CameraSubject = nil
end


 
local function UpdateCamera() ----For Updating The Camera 
SetCameraMode()
local cameraRotationCFrame = CFrame.Angles(0, cameraRotation.X, 0)*CFrame.Angles(cameraRotation.Y, 0, 0)
camera.CFrame = cameraRotationCFrame + cameraPosition + cameraRotationCFrame*Vector3.new(0, 0, cameraZoom)
camera.Focus = camera.CFrame - Vector3.new(0, camera.CFrame.p.Y, 0)
end



local lastTouchRotation = nil
local function TouchRotate(touchPositions, rotation, velocity, state) ----Touch Rotation stuff, you can play around with this
if state == Enum.UserInputState.Change or state == Enum.UserInputState.End then
local difference = rotation - lastTouchRotation
cameraRotation = cameraRotation + Vector2.new(-difference,0)*math.rad(cameraTouchRotateSpeed*cameraRotateSpeed)
		UpdateCamera()
	end
lastTouchRotation = rotation
end
 

local lastTouchScale = nil
local function TouchZoom(touchPositions, scale, velocity, state) --Zooming For Mobile
	if state == Enum.UserInputState.Change or state == Enum.UserInputState.End then
		local difference = scale - lastTouchScale
		cameraZoom = cameraZoom * (1 + difference)
		if cameraZoomBounds ~= nil then
			cameraZoom = math.min(math.max(cameraZoom, cameraZoomBounds[1]), cameraZoomBounds[2])
		else
			cameraZoom = math.max(cameraZoom, 0)
end
		UpdateCamera()
	end
	lastTouchScale = scale
end
 
local function Input()
	UpdateCamera()
end




 
local function Input(inputObject) ---This is where we process input!
	
	
	if inputObject.UserInputType == Enum.UserInputType.Keyboard then
		if inputObject.UserInputState == Enum.UserInputState.Begin then	
			if inputObject.KeyCode == Enum.KeyCode.I then
			 	cameraZoom = cameraZoom - 15
			elseif inputObject.KeyCode == Enum.KeyCode.O then
				cameraZoom = cameraZoom + 15
			end
			if cameraZoomBounds ~= nil then
				cameraZoom = math.min(math.max(cameraZoom, cameraZoomBounds[1]), cameraZoomBounds[2])
			else
				cameraZoom = math.max(cameraZoom, 0)
			end
			UpdateCamera()
		end
	end
	
		UserInputService.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
		local rotation = UserInputService:GetMouseDelta()
		cameraRotation = cameraRotation - rotation*math.rad(cameraMouseRotateSpeed)
	
	
		if inputObject.UserInputState == Enum.UserInputState.Change then -- allow us to chnage the zoom distance with the mouseWheel
			if inputObject.UserInputType == Enum.UserInputType.MouseWheel then
				if inputObject.Position.Z > 0 then
					cameraZoom = cameraZoom + 4 ---You can play around with this
			else
				cameraZoom = cameraZoom - 2.9
				end
			end
		end
end


local function PlayerChanged()
	local movement = AnchoredObject.Position - playerPosition
	cameraPosition = cameraPosition + movement
	playerPosition = AnchoredObject.Position
	UpdateCamera()
end

 

	
UserInputService.InputBegan:Connect(Input)
UserInputService.InputChanged:Connect(Input)
UserInputService.InputEnded:Connect(Input)
RunService:BindToRenderStep("PlayerChanged", Enum.RenderPriority.Camera.Value-1, PlayerChanged) ---Sart
1 Like

At line eight where is says: local Character = player.CharacterAdded:Wait()

I get an error saying:
Workspace.Script:8: attempt to index local ‘player’ (a nil value)
Also I can’t open the linked file

i forgot to mention, put this in the StarterplayerScripts, it should work then

I do not recommend using the solution I gave previously since @colbert2677 was nice enough to give you a much more elegant solution.

Though it looks like you’re looking for a forced shiftlock script.
This is what I ended up using for one of my games:

It’s an edited version of the default Roblox core camera script(s)
I’m no expert in programming such intuitive dynamic camera movement

I think I originally found how to do it this way through this post

EDIT:
For this to work, you have to place the script under StarterPlayerScripts.

Also, if you want to see the parts I edited you can do CTRL + Shift + F
Then search for “EDITED”