I’m creating a cutscene, and I want the camera to face the front of the player, or the opposite of the back of the player.
With or without the camera moving with the player, help would be appreciated.
This is my current script -
local part = workspace:WaitForChild(“Shidou”)
local finished = true
part.Touched:Connect(function(part)
if finished == false then return end
if part.Parent:IsA(“Model”) and part.Parent:FindFirstChild(“Humanoid”) then
local character = part.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if player then
if finished == true then
finished = false
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 0
local remote = game.ReplicatedStorage.shidou
remote:FireServer(character)
local animation = Instance.new(“Animation”)
animation.AnimationId = “rbxassetid://102719620025576”
local camera = workspace.Camera
camera.CameraSubject = character.Torso
game.Chat:Chat(player.Character.Head, “Huh?”, Enum.ChatColor.Red)
local animator = character.Humanoid.Animator
local anim = animator:LoadAnimation(animation)
camera.CameraType = Enum.CameraType.Attach
anim:Play()
anim:AdjustSpeed(0.35)
task.wait(1.5)
game.Chat:Chat(player.Character.Head, “My back is to the ball and I am not close enough but…”, Enum.ChatColor.Red)
task.wait(1.25)
game.Chat:Chat(player.Character.Head, “My cells… They’re telling me…”, Enum.ChatColor.Red)
task.wait(1)
anim:AdjustSpeed(0.6)
task.wait(.25)
game.Chat:Chat(player.Character.Head, “To score a…”, Enum.ChatColor.Red)
anim:AdjustSpeed(0.45)
task.wait(1.25)
game.Chat:Chat(player.Character.Head, “SUPER GOAL!”, Enum.ChatColor.Red)
task.wait(1.5)
anim:AdjustSpeed(0.8)
task.wait(2)
camera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
camera.CameraType = Enum.CameraType.Custom
task.wait(1)
finished = true
end
end
end
end)
As of now, it follows the player, however, it currently automatically faces the back of the player. I know you have to use Scriptable camera type however I’m not good with CFrame. So again, it would be forced to look at the front of the player.
local part = workspace:WaitForChild("Shidou")
local running = false -- Switched the logic from seeing if the cutscene is finished to see if the cutscene is still running to make code easier to read
part.Touched:Connect(function(part)
if running == true then return end
if part.Parent:IsA("Model") and part.Parent:FindFirstChild("Humanoid") then
local character = part.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if player then
if running ~= true then
running = true
-- Anchor the HumanoidRootPart instead of changing the walkspeed to 0 to lock the character in place
character.HumanoidRootPart.Anchored = true
local remote = game.ReplicatedStorage.shidou
remote:FireServer(character)
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://102719620025576"
-- Use currentCamera instead of workspace.Camera, as currentCamera is the camera specifically being used by the local player
local camera = workspace.CurrentCamera
camera.CameraSubject = character.Torso
game.Chat:Chat(player.Character.Head, "Huh?", Enum.ChatColor.Red)
local animator = character.Humanoid.Animator
local anim = animator:LoadAnimation(animation)
-- Set the camera type to be scriptable
camera.CameraType = Enum.CameraType.Scriptable
-- We can use a new CFrame called "offset" to place the camera where we want it relative to where the character is by multiplying it by the humanoid root part's CFrame
local offset = CFrame.new(0,3,-10)
local cameraPlacement = (character.HumanoidRootPart.CFrame * offset)
-- The first argument is to say where the camera should be in the world, and the second argument is where the camera should be pointed towards
local cameraPos = CFrame.lookAt(cameraPlacement.Position, character.Head.Position)
camera.CFrame = cameraPos
anim:Play()
anim:AdjustSpeed(0.35)
task.wait(1.5)
game.Chat:Chat(player.Character.Head, "My back is to the ball and I am not close enough but…", Enum.ChatColor.Red)
task.wait(1.25)
game.Chat:Chat(player.Character.Head, "My cells… They’re telling me…", Enum.ChatColor.Red)
task.wait(1)
anim:AdjustSpeed(0.6)
task.wait(.25)
game.Chat:Chat(player.Character.Head, "To score a…", Enum.ChatColor.Red)
anim:AdjustSpeed(0.45)
task.wait(1.25)
game.Chat:Chat(player.Character.Head, "SUPER GOAL!", Enum.ChatColor.Red)
task.wait(1.5)
anim:AdjustSpeed(0.8)
task.wait(2)
camera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
character.HumanoidRootPart.Anchored = false
camera.CameraType = Enum.CameraType.Custom
task.wait(1)
running = false
end
end
end
end)
I specifically used CFrame.lookAt in this script, however I would highly recommend you read the documentation on CFrames here as they’re incredibly useful to know when it comes to making games: CFrame | Documentation - Roblox Creator Hub