Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Preventing camera Rotation and getting spawn direction?

Asked by
Yozoh 146
5 years ago
Edited 5 years ago

1st question: How can I prevent the player from rotating their camera? I'm creating a character customize room, and I don't want the player rotating around their camera.

2nd question: Whenever my player spawns in the character customize room, they face backwards towards the Z direction. I want them to face the camera view. How can get the direction of which they spawn?

Thanks!

1 answer

Log in to vote
2
Answered by
Zafirua 1348 Badge of Merit Moderation Voter
5 years ago

How can I prevent the player from rotating their camera?

Considering the fact that you are creating a lobby camera, I will show you my preferred way of doing the following.

  • 1) Create a folder inside of Workspace. Name the folder CameraParts. Now, insert a part into the workspace and position it to your desire. Then, place the brick in the folder once you are done. Now we move on to scripting

Warning, this is a client-sided script only. Place it in StarterGui, StarterCharacterScript, StarterPlayerScipt

-- Declaration Section 
-- //Game Services 
local Workspace = game:GetService("Workspace")
local Camera = Workspace.CurrentCamera

-- //Camera Folder
local CameraFolder = Workspace:WaitForChild("CameraParts")
local CameraPart = CameraFolder:FindFirstChild("LobbyCamera1")

-- Processing Section 

repeat wait()
    Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable

Camera.CFrame = CameraPart.CFrame 

Explanation

CurrentCamera is a property of Camera which defines the Camera Object of the Local Player. Basically we are telling the server that change the CurrentCamera to CameraPart

How can get the direction of which they spawn?

This really depends on two actions. Whether you are using Roblox Spawn or Manual Spawn

If you are using the Default Roblox Spawn, then just rotating it to the desired location will get you to your goal.

However, if you are using like your own spawn script, then we would have to force the player to face the particular way.

-- Declaration Section 
-- //Game Services 
local Workspace = game:GetService("Workspace")
local Camera = Workspace.CurrentCamera
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")

-- //Camera Folder
local CameraFolder = Workspace:WaitForChild("CameraParts")
local CameraPart = CameraFolder:FindFirstChild("LobbyCamera1")

-- Processing Section 

repeat wait()
    Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable

Camera.CFrame = CameraPart.CFrame 

HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.Position, CameraPart.Position)

Explanation

HumanoidRootPart is a property of Character and a reference to point to the Humanoid's root driving part. What we are doing here is the we are updating the default humanoid position to face the camera. No matter what position the player is in, they will always face the camera.

Hope you learned something. If error still persists, fell free to comment below.

Have a lovely day of coding.
Ad

Answer this question