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

How Can I Set the Player's Camera on an Object at the Right Angle and Stop Him/Her From Zooming?

Asked by
8391ice 91
8 years ago

I am trying to make it so that when this script runs, the player's camera will be focused on an object in the Workspace. However, the camera is focused on the wrong side of the object when I want it to face the RightSurface of that object. Also, it is zoomed out WAY too far and I want to keep it zoomed at a level of my choosing and prevent the player from zooming in and out. I have no idea how to do these things; I've searched the Wiki and I haven't really found anything that could help me.

Upon entering the game, this script fires:

local data = game:GetService("DataStoreService")
local store = data:GetDataStore("Store1")

game.Players.PlayerAdded:connect(function(player)
    repeat wait() until player.PlayerGui ~= nil --Waiting until the PlayerGui and Character have been created
    local fadeOut = game.ServerStorage.Gui.FadeOutGui:Clone() --Creating a fade effect for when the player joins the game
    fadeOut.Parent = player.PlayerGui
    fadeOut.Enabled = true
    repeat wait() until player.Character ~= nil --Placing the player at some random position in the middle of nowhere until he or she clicks "Play" to enter the game
    local xRan = math.random(1000, 2000)
    local yRan = math.random(1000, 2000)
    local zRan = math.random(1000, 2000)
    player.Character.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(xRan, yRan, zRan))
    player.Character.HumanoidRootPart.Anchored = true
    local cameraSet = game.ServerStorage.Scripts.CameraTitle:Clone() --Getting the Camera script
    player:WaitForChild("Backpack")
    cameraSet.Parent = player.Backpack
    cameraSet.Disabled = false
    fadeOut.Fade.Disabled = false --When this is disabled, the script for the fade effect will activate. This is purposely placed after the Camera script from the previous line is disabled to ensure that the fade doesn't activate until the camera is facing the object.
end)

This is the Camera Script, a LocalScript:

cam = game.Workspace.Camera

cam.CameraSubject = game.Workspace.StartMenuArea.Room.Board
cam.CameraType = "Track"
cam.CoordinateFrame = game.Workspace.StartMenuArea.Room.Board.CFrame
--This is the best I've been able to do with the knowledge of cameras that I have. I want the camera to face the RightSurface of the Board as well as set the correct zoom distance and keep the player from zooming in and out until he or she has clicked "Play." How can I do this?

Any and all help is always appreciated!

1 answer

Log in to vote
0
Answered by 8 years ago

http://wiki.roblox.com/index.php?title=Camera_manipulation ^ This will help a lot more.

Also, you could give this a try:

cam = game.Workspace.CurrentCamera

local target =  game.Workspace.StartMenuArea.Room.Board

cam.CameraSubject = target
cam.CameraType = 'Scriptable'
cam.CoordinateFrame = CFrame.new(target.Position)
                     * CFrame.Angles(0, 0, 0) -- change this to the desired angle

"CFrame.Angles CFrame CFrame.Angles(number rX, number rY, number rZ)

Description: Creates a rotated CFrame using euler angles (rX, rY, rZ) in radians." - the wiki

*I've had a bit of trouble with the angles myself, so that's about as much advice as I can give you. But, you'll also want to be sure to change the camera subject back to 'game.Players.LocalPlayer.Character.Humanoid' and the camera type back to custom after they press the start button on your menu.

Hopefully this helps. Good luck!

0
This helped very much! Thank you! 8391ice 91 — 8y
Ad

Answer this question