Freecam System Help

  1. What do you want to achieve?
    Similar to how the Roblox Studio camera is set up while editing the game, I would like the player to be able to move the rotation of the camera part while holding down RMB. Outside of this specific missing feature of the camera system, my own is nearly identical, achieved via linear velocities.

  2. What is the issue?
    This is far out of my area of “expertise”, and I do not know where to start.

  3. What solutions have you tried so far?
    I have thought about and got half way through implementing key binds to rotate the camera in x direction, but because of the fast-paced nature in the game it is too clunky to be passable.

Client Code

local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local RemotesFolder = ReplicatedStorage:WaitForChild("Remotes")
local RemoteEvent = RemotesFolder:WaitForChild("RemoteEvent")

local ModulesFolder = ReplicatedStorage:WaitForChild("Modules")
local VelocityModule = require(ModulesFolder:WaitForChild("Velocity"))

local Functions = {
	
	CalculateVelocity = function(VectorDirection)
		
		local CameraModel = game.Workspace:WaitForChild("CameraModel")
		local LinearVelocity = CameraModel:WaitForChild("LinearVelocity")
		local VectorVelocity = LinearVelocity.VectorVelocity
		local CalculatedVelocity = VectorVelocity + VectorDirection
		
		return LinearVelocity, CalculatedVelocity
	end,
}

UserInputService.InputBegan:Connect(function(Input, Processed)
	if not Processed then
		
		local UserInputType = Input.UserInputType.Name
		if UserInputType == "Keyboard" then
			
			local Key = Input.KeyCode.Name
			
			if Key == "W" then
				
				local VectorDirection = Vector3.new(50, 0, 0)
				local LinearVelocity, CalculatedVelocity = Functions.CalculateVelocity(VectorDirection)
				
				VelocityModule.ChangeVelocity({
					VelocityObject = LinearVelocity,
					
					SpeedMultiplier = 1,
					VectorDirection = CalculatedVelocity
				})
				
			elseif Key == "A" then
				
				local VectorDirection = Vector3.new(0, 0, -50)
				local LinearVelocity, CalculatedVelocity = Functions.CalculateVelocity(VectorDirection)

				VelocityModule.ChangeVelocity({
					VelocityObject = LinearVelocity,

					SpeedMultiplier = 1,
					VectorDirection = CalculatedVelocity
				})
				
			elseif Key == "S" then
				
				local VectorDirection = Vector3.new(-50, 0, 0)
				local LinearVelocity, CalculatedVelocity = Functions.CalculateVelocity(VectorDirection)

				VelocityModule.ChangeVelocity({
					VelocityObject = LinearVelocity,

					SpeedMultiplier = 1,
					VectorDirection = CalculatedVelocity
				})
			
			elseif Key == "D" then
				
				local VectorDirection = Vector3.new(0, 0, 50)
				local LinearVelocity, CalculatedVelocity = Functions.CalculateVelocity(VectorDirection)

				VelocityModule.ChangeVelocity({
					VelocityObject = LinearVelocity,

					SpeedMultiplier = 1,
					VectorDirection = CalculatedVelocity
				})
				
			elseif Key == "E" then
				
				local VectorDirection = Vector3.new(0, 50, 0)
				local LinearVelocity, CalculatedVelocity = Functions.CalculateVelocity(VectorDirection)

				VelocityModule.ChangeVelocity({
					VelocityObject = LinearVelocity,

					SpeedMultiplier = 1,
					VectorDirection = CalculatedVelocity
				})
				
			elseif Key == "Q" then
				
				local VectorDirection = Vector3.new(0, -50, 0)
				local LinearVelocity, CalculatedVelocity = Functions.CalculateVelocity(VectorDirection)

				VelocityModule.ChangeVelocity({
					VelocityObject = LinearVelocity,

					SpeedMultiplier = 1,
					VectorDirection = CalculatedVelocity
				})
				
			end
		else

		end
	end
end)

UserInputService.InputEnded:Connect(function(Input, Processed)
	if not Processed then
		
		local UserInputType = Input.UserInputType.Name
		if UserInputType == "Keyboard" then
			
			local Key = Input.KeyCode.Name
			
			if Key == "W" then

				local VectorDirection = Vector3.new(-50, 0, 0)
				local LinearVelocity, CalculatedVelocity = Functions.CalculateVelocity(VectorDirection)

				VelocityModule.ChangeVelocity({
					VelocityObject = LinearVelocity,

					SpeedMultiplier = 1,
					VectorDirection = CalculatedVelocity
				})

			elseif Key == "A" then

				local VectorDirection = Vector3.new(0, 0, 50)
				local LinearVelocity, CalculatedVelocity = Functions.CalculateVelocity(VectorDirection)

				VelocityModule.ChangeVelocity({
					VelocityObject = LinearVelocity,

					SpeedMultiplier = 1,
					VectorDirection = CalculatedVelocity
				})

			elseif Key == "S" then

				local VectorDirection = Vector3.new(50, 0, 0)
				local LinearVelocity, CalculatedVelocity = Functions.CalculateVelocity(VectorDirection)

				VelocityModule.ChangeVelocity({
					VelocityObject = LinearVelocity,

					SpeedMultiplier = 1,
					VectorDirection = CalculatedVelocity
				})

			elseif Key == "D" then

				local VectorDirection = Vector3.new(0, 0, -50)
				local LinearVelocity, CalculatedVelocity = Functions.CalculateVelocity(VectorDirection)

				VelocityModule.ChangeVelocity({
					VelocityObject = LinearVelocity,

					SpeedMultiplier = 1,
					VectorDirection = CalculatedVelocity
				})

			elseif Key == "E" then
					
				local VectorDirection = Vector3.new(0, -50, 0)
				local LinearVelocity, CalculatedVelocity = Functions.CalculateVelocity(VectorDirection)

				VelocityModule.ChangeVelocity({
					VelocityObject = LinearVelocity,

					SpeedMultiplier = 1,
					VectorDirection = CalculatedVelocity
				})

			elseif Key == "Q" then

				local VectorDirection = Vector3.new(0, 50, 0)
				local LinearVelocity, CalculatedVelocity = Functions.CalculateVelocity(VectorDirection)

				VelocityModule.ChangeVelocity({
					VelocityObject = LinearVelocity,

					SpeedMultiplier = 1,
					VectorDirection = CalculatedVelocity
				})
					
			end
			
		end
	end
end)

VelocityModule

local DebrisService = game:GetService("Debris")

local VelocityModule = {}

function VelocityModule.ChangeVelocity(Data)
	
	local VelocityObject = Data.VelocityObject
	
	local SpeedMultiplier = Data.SpeedMultiplier
	local VectorDirection = Data.VectorDirection
	
	VelocityObject.VectorVelocity = VectorDirection * SpeedMultiplier
end

return VelocityModule

Thank you!

1 Like