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

How can I make a function to focus their camera on a part or Vector3?

Asked by 5 years ago

Alright so my current game needs a tutorial. However there are many buttons on the ground. This is a tycoon game. I want to offer new players a decent tutorial to how to use/play the game. I have a button on the ground (of many) that allows a player to become owner of the tycoon when it's been stepped on.

I've tried so many different ways to approach this problem but none of them are actually effective. The closest I've gotten is

-- TutorialLoader.lua [ Local Script ]
while game.Workspace.OwnerButton.Value == false do -- No owner ?
    ShowMe(game.Workspace.Baseplate) -- Look at button
    wait(1 / 3)
end

function ShowMe(part)
    game.Workspace.CurrentCamera.CameraSubject = part -- I can't see myself. >_<
end

game.Workspace.OwnerButton.Touched:connect(function()
    game.Workspace.OwnerButton.Value = true -- We've got an owner !
end)

The button is seen by the camera, however it's very hard to navigate to it as the player can't see if the character moving towards are further away.

Their camera will be mainly first person locked. So how can I get a player that is in firstperson to have their camera/screen/mouse locked onto the button. I know this might seem silly, but since it's hard for me to explain in text. But imagine a part on the ground and a player needs to reach it. The player's mouse will be locked onto it.

I don't know if camera.Focus or camera.CameraSubject or camera.CameraType is what i need to be working on. Making a camera lock onto something and not move off the player is so confusing. If someone has knowledge on how I can make my player lock onto the owner button by calling this ( or similar )

ShowMe(game.Workspace.OwnerButton)

I guess you can say it's almost like an aimbot.

0
Instead of requiring them to walk to the button, you could move their character manually Amiaa16 3227 — 5y
0
I actually thought of that before. But then I realized one wouldn't really remember if the work was done for them and that locking onto a part would be the best option for my type of game. LucarioZombie 291 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

I did some researching and found the easiest method is a one liner.

game.Workspace.CurrentCamera.CoordinateFrame = CFrame.new(game.Workspace.CurrentCamera.CoordinateFrame.p, PART.CFrame.p)

-- TutorialLoader.lua [ Local Script ]
while game.Workspace.OwnerButton.Value == false do -- No owner ?
    ShowMe(game.Workspace.Baseplate) -- Look at button
    wait(1 / 3)
end

function ShowMe(part)
    game.Workspace.CurrentCamera.CoordinateFrame = CFrame.new(game.Workspace.CurrentCamera.CoordinateFrame.p, part.CFrame.p) -- Confirmed working
end

game.Workspace.OwnerButton.Touched:connect(function()
    game.Workspace.OwnerButton.Value = true -- We've got an owner !
end)
Ad

Answer this question