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.

Main.UIS.InputBegan:Connect(function(Input,IsTyping)
	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
			wait()
		end
	elseif Input.KeyCode == Enum.KeyCode.S then
		warn("Crouch")
	elseif Input.KeyCode == Enum.KeyCode.A and not IsFalling() then
		game.Players.LocalPlayer:Move(Vector3.new(-1,0,0),true)
	elseif Input.KeyCode == Enum.KeyCode.D and not IsFalling() then
		game.Players.LocalPlayer:Move(Vector3.new(1,0,0),true)
	end
end)

Main.UIS.InputEnded:Connect(function(Input,IsTyping)
	if IsTyping then return end
	
	if Input.KeyCode == Enum.KeyCode.D then
		game.Players.LocalPlayer:Move(Vector3.new(0,0,0),true)
	elseif Input.KeyCode == Enum.KeyCode.A then
		game.Players.LocalPlayer:Move(Vector3.new(0,0,0),true)
	end
end)

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
	end

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

	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
	else
		-- 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)
	end
	local norm = math.sqrt(c*c + s*s)
	return Vector3.new(
		(c*cameraRelativeMoveVector.x + s*cameraRelativeMoveVector.z)/norm,
		0,
		(c*cameraRelativeMoveVector.z - s*cameraRelativeMoveVector.x)/norm
	)
end

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)
			end

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

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