It looks like there might be a slight misunderstanding or typo in your correction. In your original request, you wanted the character to always face the direction the camera is pointing (like forced shift-lock), but now you've said "force the character to always face in behind of the game." This phrasing is a bit unclear—could you mean:
The character should face behind the camera (e.g., away from where the camera is looking)?
Or perhaps you meant "behind the player" or "the back of the game world" (e.g., a fixed direction)?
Based on the context of an over-the-shoulder camera system, I'll assume you want the character to face the opposite direction of the camera's look vector. This would mean the character is always looking "behind" relative to the camera's view, which could create a unique third-person effect where the character faces away from the action.
If this isn't what you intended, please clarify! For now, I'll update the code accordingly:
The camera will still be displaced slightly to the right of the player (as in your original request).
The character will now be forced to face the opposite direction of the camera's look vector (e.g., if the camera is looking forward, the character looks backward).
Here's the updated script. I've modified the part where the character's rotation is set to invert the direction.
📜 Updated LocalScript: OverTheShoulderCamera.lua
Place this in StarterPlayer > StarterPlayerScripts as a LocalScript.
lua
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local player = Players.LocalPlayer
local camera = workspace.CurrentCamera
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local rootPart = character:WaitForChild("HumanoidRootPart")
-- Settings
local CAMERA_OFFSET = Vector3.new(2, 1.5, 6) -- Right, Up, Back (slightly to the right of the player)
local SENSITIVITY = 0.002
local MAX_Y_ANGLE = math.rad(80)
local MIN_Y_ANGLE = math.rad(-80)
-- Internal
local cameraAngleX = 0
local cameraAngleY = 0
local isRightMouseDown = false
-- Disable default camera and controls
camera.CameraType = Enum.CameraType.Scriptable
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
-- Lock mouse on input
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.MouseButton2 then
isRightMouseDown = true
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
end
end)
UserInputService.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton2 then
isRightMouseDown = false
end
end)
-- Mouse movement
UserInputService.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement then
local delta = input.Delta
cameraAngleX -= delta.X * SENSITIVITY
cameraAngleY = math.clamp(cameraAngleY - delta.Y * SENSITIVITY, MIN_Y_ANGLE, MAX_Y_ANGLE)
end
end)
-- Update camera and character rotation
RunService.RenderStepped:Connect(function()
if not character or not rootPart then return end
-- Calculate camera CFrame
local startCFrame = CFrame.new(rootPart.Position) * CFrame.Angles(0, cameraAngleX, 0) * CFrame.Angles(cameraAngleY, 0, 0)
local cameraCFrame = startCFrame:ToWorldSpace(CFrame.new(CAMERA_OFFSET))
local cameraFocus = startCFrame:ToWorldSpace(CFrame.new(CAMERA_OFFSET.X, CAMERA_OFFSET.Y, -10000))
camera.CFrame = CFrame.new(cameraCFrame.Position, cameraFocus.Position)
-- Force character to face the OPPOSITE of the camera direction (inverted look vector)
local lookVector = Vector3.new(math.sin(cameraAngleX), 0, math.cos(cameraAngleX)).Unit -- Original look vector
local invertedLookVector = -lookVector -- Invert it to face "behind"
rootPart.CFrame = CFrame.new(rootPart.Position, rootPart.Position + invertedLookVector) -- Character faces the inverted direction
end)
✅ Key Changes and Explanation
Character Facing Direction: In the original code, the character faced the same direction as the camera (e.g., rootPart.CFrame = CFrame.new(rootPart.Position, rootPart.Position + lookVector)). Now, I've inverted the look vector by using -lookVector, so the character always faces the opposite way. For example:
If the camera is looking forward (positive Z), the character will look backward (negative Z).
Camera Behavior: The camera is still offset to the right of the player and allows vertical movement (up/down with the mouse), just as you requested.
Why This Might Fit: This creates an effect where the character is always "looking behind" relative to the camera's view, which could be what you meant by "behind of the game." It's unusual for a standard over-the-shoulder setup, but it could work for a custom game mechanic (e.g., a character that's always retreating or facing away).
🛠 Testing and Troubleshooting
Test in Roblox Studio: Run the game and move your mouse to rotate the camera. The character should now face away from where the camera is pointing.
If This Isn't Right: If you meant something else (e.g., the character facing a fixed direction like the back of the map), let me know more details, and I can refine it further. For instance:
If you want the character to face a specific global direction (e.g., always north), I can hardcode that.
If it was a typo and you meant to keep the original behavior, I can revert it.
Feel free to reply with more clarifications or additional features! 😊