Can anyone explain me how can I make a camera like Booga Booga for example, when you move your mouse character is still facing forwards.
In this script only issue I am facing is that I need to hold the right button to move my characters LookVector
local cam = workspace.CurrentCamera;
local plr = game:GetService("Players").LocalPlayer;
game:GetService("RunService").RenderStepped:connect(function()
if (plr.Character) then
local root = plr.Character.HumanoidRootPart;
if (root) then
root.CFrame = CFrame.new(root.CFrame.p,root.CFrame.p+Vector3.new(cam.CFrame.lookVector.X,0,cam.CFrame.lookVector.Z));
end
end
end)
That code looks like it should work fine. I use a simple function to implement this with RunService:BindToRenderStep on the client:
local workspaceService = game:GetService("Workspace")
local playersService = game:GetService("Players")
local runService = game:GetService("RunService")
local localPlayer = playersService.LocalPlayer
local camera = workspaceService.CurrentCamera
runService:BindToRenderStep("UpdateCharacter", Enum.RenderPriority.Character.Value, function()
local character = localPlayer.Character
if not character then return end
local primaryPart = character.PrimaryPart
if not primaryPart then return end
-- rotate character
local lookVector = camera.LookVector
local position = primaryPart.Position
local lookAt = position + Vector3.new(lookVector.X, 0, lookVector.Z).Unit
primaryPart.CFrame = CFrame.new(position, lookAt)
end)
In other words, do you want your mouse to be locked in the centre of your screen and your character to rotate relative to the mouse’s movement delta every frame, like shift lock?
That script works exactly the same way as the script I provided I want to do so when you move the mouse it also changes the character’s direction and not when I hold the button.
This custom camera code should be placed inside a LocalScript named CameraScript inside StarterPlayer > StarterPlayerScripts. You can change the sensitivity, world offset, and local offset as you wish. Feel free to read through the script and break it apart to grasp a better understanding of how it works.
-- services:
local workspaceService = game:GetService("Workspace")
local runService = game:GetService("RunService")
local playersService = game:GetService("Players")
local userInputService = game:GetService("UserInputService")
-- config:
local SENSITIVITY = 0.4
local WORLD_OFFSET = Vector3.new(0, 2, 0)
local LOCAL_OFFSET = Vector3.new(0, 1.75, 9.5)
-- variables:
local camera = workspaceService.CurrentCamera
local localPlayer = playersService.LocalPlayer
local xAngle = 0
local yAngle = 0
-- main:
-- handle camera moving
userInputService.InputChanged:Connect(function(input, isProcessed)
-- validate input
if isProcessed then return end
if input.UserInputType ~= Enum.UserInputType.MouseMovement then return end
-- get delta
local delta = input.Delta
local deltaX = delta.X
local deltaY = delta.Y
-- update angles
xAngle = xAngle - deltaX * SENSITIVITY
yAngle = math.clamp(yAngle - deltaY * SENSITIVITY, -80, 80)
end)
-- handle camera update
runService:BindToRenderStep("CameraUpdate", Enum.RenderPriority.Camera.Value, function()
-- get necessary data
local cameraSubject = camera.CameraSubject
if not cameraSubject then return end
local isLocalPlayer = false
local subject
local ignoredInstance
-- check camera subject class
if cameraSubject:IsA("Humanoid") then
ignoredInstance = cameraSubject.Parent
if not ignoredInstance:IsA("Model") then return end
subject = ignoredInstance.PrimaryPart
if not subject then return end
if localPlayer.Character == ignoredInstance and cameraSubject.Health > 0 then
isLocalPlayer = true
end
elseif cameraSubject:IsA("BasePart") then
subject = cameraSubject
ignoredInstance = cameraSubject
else return end
-- get positioned, world offset, and rotated cframe
local xAngleCFrame = CFrame.Angles(0, math.rad(xAngle), 0)
local anglesCFrame = xAngleCFrame:ToWorldSpace(CFrame.Angles(math.rad(yAngle), 0, 0))
local cameraPosition = subject.Position + WORLD_OFFSET
local startCFrame = CFrame.new(cameraPosition):ToWorldSpace(anglesCFrame)
-- get camera focus and local offset cframe
local cameraCFrame = startCFrame:ToWorldSpace(CFrame.new(LOCAL_OFFSET))
local cameraFocus = cameraCFrame:ToWorldSpace(CFrame.new(0, 0, -LOCAL_OFFSET.Z))
-- assign camera properties
camera.Focus = cameraFocus
camera.CFrame = cameraCFrame
camera.CFrame = cameraCFrame:ToWorldSpace(CFrame.new(0, 0, -camera:GetLargestCutoffDistance({ignoredInstance})))
-- rotate character
if isLocalPlayer then
local primaryPartCFrame = ignoredInstance:GetPrimaryPartCFrame()
local newCFrame = CFrame.new(primaryPartCFrame.Position):ToWorldSpace(xAngleCFrame)
ignoredInstance:SetPrimaryPartCFrame(newCFrame)
end
end)
-- init
userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
You can learn more about camera manipulation here.
What I do sometimes that works pretty well is to just set the Player.CameraMode to Enum.CameraMode.LockFirstPerson, and then set the max and min camera zoom values to eight or something (to keep it zoomed out and not going back to first person mode) . You can make it work even better by setting the character’s CameraOffset to some offset like (1,0,0) to give it that nice view that third person view games usually have. The nice thing about this method is that you don’t have to continually set it each frame.