Hello Everyone!
Right now i’m making a horror game. & i’m trying to figure out how to make the player’s camera look
at something but still keeping its original position.
so basically in my game the player would be driving a car to a gas station,
& at a certain distance it will look at the gas station.
I already used CFrame.LookAt() what im trying to get is to make the player’s camera to look at the gas station but also being on the original position (sorry if its a bit confusing)
you can achieve this by setting the camera’s CFrame to a new CFrame that combines its current position with the look direction towards the gas station. Here’s a basic example:
local camera = workspace.CurrentCamera
local OriginalPosition = camera.CFrame.Position
local GasStationPosition = workspace.Station.Position -- Replace with the real path to your gas station
camera.CFrame = CFrame.lookAt(OriginalPosition, GasStationPosition)
You can put OriginalPosition and camera.CFrame = CFrame.lookAt(OriginalPosition, GasStationPosition) in a loop to keep the current position if the player is moving.
Hello! i already found a solution to my problem by welding a part to the character and setting the CFrame of the Player’s camera to the CFrame of the Fake Camera’s CFrame
and also using CFrame.LookAt() so the Fake Camera’s CFrame looks at the Gas Station.
local player = game:GetService("Players").LocalPlayer
local camera = workspace.CurrentCamera
local RS = game:GetService("RunService")
local function LookWithCamera(camera, pos)
--camera.CameraType = Enum.CameraType.Scriptable
local CameraLook = RS.RenderStepped:Connect(function()
--camera.CFrame = CFrame.new(player.Character.PrimaryPart.Position + 1.5 * Vector3.yAxis + 1.5 * pos.Unit, pos)
--camera.CFrame = CFrame.new(player.Character.Head.Position, pos)
camera.CFrame = CFrame.new(camera.CFrame.Position, pos)
end)
return CameraLook
end
local function CameraLookTriggersHelper(startz, endz, camera, pos)
local inProgress = false
local StepFunction
startz.Touched:Connect(function(otherPart)
if not inProgress and otherPart.Name == "HumanoidRootPart" then
if otherPart.Parent == player.Character then
inProgress = true
StepFunction = LookWithCamera(camera, pos)
end
end
end)
endz.Touched:Connect(function(otherPart)
if inProgress and otherPart.Name == "HumanoidRootPart" then
if otherPart.Parent == player.Character then
inProgress = false
StepFunction:Disconnect()
--camera.CameraType = Enum.CameraType.Follow
end
end
end)
end
local startZone = workspace:WaitForChild("CameraLookStart")
local endZone = workspace:WaitForChild("CameraLookEnd")
local ThingToLookAt = workspace:WaitForChild("Thing")
CameraLookTriggersHelper(startZone, endZone, camera, ThingToLookAt.CFrame.Position)
Use the commented line camera.CFrame = CFrame.new(player.Character.Head.Position, pos) to instead get a first person view