ControlScript and CameraScript are a maze

About one or two weeks ago I wanted to modify the CameraScript code to suit my needs. I looked through the code and to my surprise I found out that the code from the CameraScript and its children together existed out of ~4500 lines of code. I looked through it to find out how the shift lock mode code worked, but quickly after gave up because I couldn’t find my way through the code. The code seems to be really split apart up to the point that I find it hard to put all the pieces together. For example, there are a lot of functions that do not seem to do more than just toggle other functions or adjust a single variable:

		MenuOpenedConn = GuiService.MenuOpened:connect(function()
			this:ResetInputStates()
		end)

		workspaceChangedConn = workspace.Changed:connect(function(prop)
			if prop == "CurrentCamera" then
				onCurrentCameraChanged()
			end
		end)
		onCurrentCameraChanged()

		ShiftLockToggleConn = ShiftLockController.OnShiftLockToggled.Event:connect(function()
			this:UpdateMouseBehavior()
		end)

It seems like the code also instantiates some objects here and there which do not get parented (e.g. the mSignaler in the ClickToMove at line 51), making it even harder to visualize the whole system. I do not know what all the code is needed for, but I believe that 4500 lines of code for camera controls is a bit too much.

So today I thought I’d take a look at the ControlScript instead to figure out how the Roblox characters move. Yet again I was surprised to find out that all the code for this system existed out of ~1700 lines of code. I started my journey through the code to find the information I needed. First I searched for ‘ContextActionService’ because I thought the input keys would be bound to a function to make the character move. Through that I found the ‘moveForwardFunc’, leading me one step closer. I decided to search for that word instead. All it lead to was a function that set the ‘forwardValue’ variable, but fortunately I saw the ‘AddToPlayerMovement’ function a few lines above it. Searching for that function lead me to a function that only did one thing: edit the ‘moveValue’. Searching for ‘moveValue’ lead me to a function with an ‘adjustedMoveValue’ variable and that function also called some ‘moveFunc’, so I decided to look for that function instead. moveFunc was apparently a shortcut for LocalPlayer.Move even though it was only used once. So after looking for at least seven different words, I finally managed to figure out that Robloxians move through the ‘Move’ method. It should not be that difficult.

Both the CameraScript and ControlScript were surprisingly difficult to navigate through, too difficult in my opinion. I do not know what all the code is needed for, but I do not think that this much code is required for two seemingly easy mechanics. My request is to try to cut down on the lines of code for these two playerscripts and tying the code together in a better way. If I’m having a hard time analyzing the code, then there are probably a ton of other people who are also having an insanely difficult time finding the pieces of code they’re looking for.

Thanks for reading this long post,
– Zomebody

20 Likes

Yeah, I can never find anything useful in there, so I always just write my own camera and control scripts

2 Likes

They should be reorganized in a way that makes it easy for developers to plug in their own code. Maybe even have some bindable API so that developers don’t have to edit the actual scripts (so they can get updates when they come out).

7 Likes

Only thing I’ve wanted is to be able to easily enable/disable movement. At some point I just gave up and created my own control script. Shouldn’t be needed for such a small thing :confused:

1 Like
ControlScript.Disabled = true

This worked for me xD

1 Like

What I coincidence, I was looking through these yesterday as well and just gave up in the end.

Wanted to modify both scripts for my game, but it was just too confusing jumping in and out of the modules / functions.

I had a very similar experience a while ago when I was trying to figure out how parts of the camera script work.

Related:

I also have no idea what that ghost-comment at the end of the conversation is

I might redesign some stuff if I’m bored enough, I’ll see.