Alm_st
(Alm_st)
July 30, 2022, 8:59pm
1
I want the camera just to look at the players Y and Z position with a constant X value. The script works if I do not have a constant x value.
local lookAt = Vector3.new(-35.375,game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart").Position.Y, game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart").Position.Z)
camera.CFrame = CFrame.new(Vector3.new(workspace.townCenterLeftExit.Position.X + 20,25,game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart").Position.Z + 15), lookAt)
``` This updates every frame
```lua
local lookAt = game.Players.LocalPlayer.Character.HumanoidRootPart.Position
camera.CFrame = CFrame.new(Vector3.new(workspace.townCenterLeftExit.Position.X + 20,25,game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart").Position.Z + 15), lookAt)
This one works, but is not what I am looking for
if you want the camera to stay in the same position, you could do something like
local humanoidRootPartPosition = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart").Position
local newCameraPosition = Vector3.new(workspace.townCenterLeftExit.Position.X + 20, 25, humanoidRootPartPosition.Z + 15)
camera.CFrame = CFrame.new(newCameraPosition)
camera.LookAt(newCameraPosition, Vector3.new(-35.375, humanoidRootPartPosition.Y, humanoidRootPartPosition.Z))
which I think should work. Tell me if it doesn’t work
Oh my bad i did not read the bottom text. Try
local xValue = math.rad(271) -- whatever fixed value you want
local _, playerYDirection, playerZDirection = camera.CFrame:ToOrientation()
camera.CFrame = CFrame.new(camera.Position) * CFrame.fromOrientation(xValue, playerYDirection, playerZDirection)
which will definitely work
Alm_st
(Alm_st)
July 30, 2022, 9:56pm
5
This one does move the camera, but it spins at 10000 mph. Makes it unplayable. Here what I’m trying to make is a “2d” game where the camera follows the player, but if the player gets too close to the side of the map the camera will stop moving
Alm_st
(Alm_st)
July 30, 2022, 10:01pm
6
Here is my code base
local runService = game:GetService("RunService")
local camera = game.Workspace.CurrentCamera
local lookAt = Vector3.new()
local beAt = Vector3.new()
camera.CameraType = Enum.CameraType.Scriptable
runService.Heartbeat:Connect(function()
local humanoidRootPartPosition = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart").Position
--if (humanoidRootPartPosition-workspace.townCenterLeftExit.Position).Magnitude <= 20 then
lookAt = game.Players.LocalPlayer.Character.HumanoidRootPart.Position
beAt = Vector3.new(game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart").Position.X,25,game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart").Position.Z + 15)
camera.CFrame = CFrame.new(beAt, lookAt)
end)
ah in that case this should work
local xValue = math.rad(271) -- whatever fixed value you want
local _, playerYDirection, playerZDirection = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart").CFrame:ToOrientation()
camera.CFrame = CFrame.new(camera.Position) * CFrame.fromOrientation(xValue, playerYDirection, playerZDirection)