I’m trying to make a Baldi’s Basic’s fan-game on Roblox and was trying to recreate the camera flipping from the original game. Basically, whenever the player holds down space, the camera turns around and flips to the opposite direction the player is facing. The player’s movement isn’t affected and holding down W while flipping the camera will make the player continue to move in the same direction, essentially moving backwards. I’ve tried to also attach a video demostrating this.
Uploading: 2024-12-05 14-27-57.mp4…
Upon flipping your camera CFrame call something like Humanoid:Move( direction here, based on HumanoidRootPart.CFrame.LookVector OR Humanoid.MoveDirection ), keep track of MoveDirection changes and edit them until player will release spacebar button
Place this script inside a LocalScript in StarterPlayerScripts
:
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local camera = workspace.CurrentCamera
local isCameraFlipped = false
-- Updates the camera to flip it around the player's direction
local function updateCamera()
if not player.Character or not player.Character:FindFirstChild("HumanoidRootPart") then
return
end
local rootPart = player.Character.HumanoidRootPart
local playerCFrame = rootPart.CFrame
if isCameraFlipped then
-- Flip the camera 180 degrees
camera.CFrame = CFrame.new(camera.CFrame.Position, playerCFrame.Position - playerCFrame.LookVector * -1)
else
-- Reset the camera to face forward
camera.CFrame = CFrame.new(camera.CFrame.Position, playerCFrame.Position + playerCFrame.LookVector)
end
end
-- Handle input events
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.Space then
isCameraFlipped = true
updateCamera()
end
end)
UserInputService.InputEnded:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.Space then
isCameraFlipped = false
updateCamera()
end
end)
-- Keep updating the camera while the spacebar is held
RunService.RenderStepped:Connect(function()
if isCameraFlipped then
updateCamera()
end
end)
1 Like