How to make custom movement script?

Heyo working on my own script for movement I might ditch it and just go back to using the default Roblox script, but wanted to try and make my own so far i’ve done this.

	if IsTyping then return end
	if Input.KeyCode == Enum.KeyCode.W then
		Main.Humanoid.Jump = true
		while IsKeyDown(Enum.KeyCode.W) do
			Main.Humanoid.Jump = true
	elseif Input.KeyCode == Enum.KeyCode.S then
	elseif Input.KeyCode == Enum.KeyCode.A and not IsFalling() then
	elseif Input.KeyCode == Enum.KeyCode.D and not IsFalling() then

	if IsTyping then return end
	if Input.KeyCode == Enum.KeyCode.D then
	elseif Input.KeyCode == Enum.KeyCode.A then

I’ve been trying to understand how the code works in the ControlModule and then just kind of applying it here in my code and it seems to work some issues though are that I don’t really understand how the moveVector variable is used and I’m not sure how the camera is updated

1 Like

I’m not seeing any moveVector variable?

If you have a custom CameraScript, then that’s where the camera is updated. If not, it’s updated in the default CameraScript. It appears automatically in Players.Player1.PlayerScripts when the game runs.

I think I may have been a bit confusing so sorry, but I’m not talking about a variable in my script I’m talking about the one in the Roblox one for ControlModule there’s a variable called moveVector, Anyways basically when turning DevComputerMovementMode to Scriptable it obviously disables controls and stuff which is why I made my own code however I realized that it also messes with the camera and I was guessing to fix it I had to do something with this code which is in the ControlModule btw

local function calculateRawMoveVector(humanoid, cameraRelativeMoveVector)
	local camera = Workspace.CurrentCamera
	if not camera then
		return cameraRelativeMoveVector

	if humanoid:GetState() == Enum.HumanoidStateType.Swimming then
		return camera.CFrame:VectorToWorldSpace(cameraRelativeMoveVector)

	local c, s
	local _, _, _, R00, R01, R02, _, _, R12, _, _, R22 = camera.CFrame:GetComponents()
	if R12 < 1 and R12 > -1 then
		-- X and Z components from back vector.
		c = R22
		s = R02
		-- In this case the camera is looking straight up or straight down.
		-- Use X components from right and up vectors.
		c = R00
		s = -R01*math.sign(R12)
	local norm = math.sqrt(c*c + s*s)
		(c*cameraRelativeMoveVector.x + s*cameraRelativeMoveVector.z)/norm,
		(c*cameraRelativeMoveVector.z - s*cameraRelativeMoveVector.x)/norm

And then a couple lines down there’s this code

		-- If not, move the player
		-- Verification of vehicleConsumedInput is commented out to preserve legacy behavior,
		-- in case some game relies on Humanoid.MoveDirection still being set while in a VehicleSeat
		--if not vehicleConsumedInput then
			if cameraRelative then
				moveVector = calculateRawMoveVector(self.humanoid, moveVector)

			self.moveFunction(Players.LocalPlayer, moveVector, false)

Edit: Also here’s the issue I’m having. Here’s what should happen with my camera

Using WorldToScreePoint I check the distance between the player and the edge of the screen however when the ControlModule is disabled the camera seems to not work the same