Hello, reader!
I am currently working on a build-mode camera (actually just to learn stuff, not for a game). I made the camera block move but when it came to changing its orientation to the mouse, I got stuck. I tried hard on experimenting with many things.
My script:
local runService = game:GetService("RunService")
local userInputService = game:GetService("UserInputService")
local replicatedStorage = game:GetService("ReplicatedStorage")
local changeHumanoidProperties = replicatedStorage.changeHumanoidProperties
local player = game.Players.LocalPlayer
local character = player.Character
local HRP = character:WaitForChild("HumanoidRootPart")
local humanoid = character:WaitForChild("Humanoid")
local defaultWalkSpeed = humanoid.WalkSpeed
local defaultJumpPower = humanoid.JumpPower
local mouse = player:GetMouse()
local camera = workspace.CurrentCamera
local buildCam = workspace.BuildCam
local isInCamera = false
local toggleButton = false
local isRightClick = false
local wKey = false
local aKey = false
local sKey = false
local dKey = false
local qKey = false
local eKey = false
script.Parent.MouseButton1Click:Connect(function()
if not toggleButton then
isInCamera = true
script.Parent.Text = "Exit Build Mode"
changeHumanoidProperties:FireServer("WalkSpeed", 0)
changeHumanoidProperties:FireServer("JumpPower", 0)
toggleButton = true
else
isInCamera = false
script.Parent.Text = "Enter Build Mode"
changeHumanoidProperties:FireServer("WalkSpeed", defaultWalkSpeed)
changeHumanoidProperties:FireServer("JumpPower", defaultJumpPower)
toggleButton = false
end
end)
userInputService.InputBegan:Connect(function(input, isProcessed)
if isProcessed then return end
if isInCamera then
if input.KeyCode == Enum.KeyCode.W then
wKey = true
elseif input.KeyCode == Enum.KeyCode.A then
aKey = true
elseif input.KeyCode == Enum.KeyCode.S then
sKey = true
elseif input.KeyCode == Enum.KeyCode.D then
dKey = true
elseif input.KeyCode == Enum.KeyCode.Q then
qKey = true
elseif input.KeyCode == Enum.KeyCode.E then
eKey = true
end
end
end)
userInputService.InputEnded:Connect(function(input, isProcessed)
if isProcessed then return end
if input.KeyCode == Enum.KeyCode.W then
wKey = false
elseif input.KeyCode == Enum.KeyCode.A then
aKey = false
elseif input.KeyCode == Enum.KeyCode.S then
sKey = false
elseif input.KeyCode == Enum.KeyCode.D then
dKey = false
elseif input.KeyCode == Enum.KeyCode.Q then
qKey = false
elseif input.KeyCode == Enum.KeyCode.E then
eKey = false
end
end)
runService.RenderStepped:Connect(function()
if isInCamera then
camera.CFrame = buildCam.CFrame
end
if wKey then
buildCam.Position = buildCam.Position + Vector3.new(0,0,-0.1)
end
if aKey then
buildCam.Position = buildCam.Position + Vector3.new(-0.1,0,0)
end
if sKey then
buildCam.Position = buildCam.Position + Vector3.new(0,0,0.1)
end
if dKey then
buildCam.Position = buildCam.Position + Vector3.new(0.1,0,0)
end
if qKey then
buildCam.Position = buildCam.Position + Vector3.new(0,-0.1,0)
end
if eKey then
buildCam.Position = buildCam.Position + Vector3.new(0,0.1,0)
end
end)
I deleted the camera move part from the script because it wasn’t working. How can I make it like the block’s orientation changes to where the mouse is looking at? I would love to hear an explanation.
Thanks in advance,
-pranvexploder.
P.S. I already read this topic, but it came to no use for me.@goldenstein64’s reply worked, but that style couldn’t be assigned to a part.