Sunday 26 February 2012

Test

Test...Requirements:
-----------------

 - Basic Scripting Knowledge
 - How to access the CurrentCamera
 - Understanding of LocalScripts
 - Understanding of For loops
 - Basic GUI Creation Knowledge
 - Roblox Studio
 - CFrame Knowledge


 [Best viewed with the forum enhancer]

 Introduction
---------------

 Welcome guys, our lesson plan here is to first get all the client side stuff done first. Like inserting the scripts and making the GUI's. We will then get into the coding, it is quite simple. This tutorial is for your learning purposes, please do not redistribute it.

 Creating The GUI
---------------------

 First we should think of descriptive names for the GUI. I named my ScreenGui "IntroCover" and my Frame "Cover". The reason we are making this GUI is to restrict access to clicking and right clicking. This prevents the user from doing any harm to the intro.

 Set the Frame's size(Scale not Offset) to 1, on both the X and Y Axis. This will cover the whole screen, next we want events to not be passed through. So we will be checking the Active property making it true. This will disallow any clicks that are fired while the frame's state is visible.

 Inserting The Script, Getting Into The Good Stuff
 --------------------------------------------------------

 We will be using a LocalScript so we can access the players CurrentCamera. Lets insert this script into the StarterPack.

 ** Note: if you want to use this with a tool or when a player first enters you will place it in the lighting then clone it when the players enters/selects the tool. **

 This localscript will control our camera's movement, before we get started with scripting we need a few points of interest on your map. So get about 4 points using a 1x1 block, you want it's position. So copy that and place it somewhere safe, we will be using it later.

 Lets get started shall we? We want to declare three variables, tha player's PlayerGui and the players Character and The Players Camera, four if you want to shorten the typing to get to the local player.

    wait()
    local Player = game.Players.LocalPlayer
    local Char = Player.Character
    local Cam = game.Workspace.CurrentCamera
    local ICover = Player.PlayerGui.IntroCover -- Replace intro cover with whatever you used for your Gui's Name
   
Now we must make the player not able to move, We do this by setting the players walkspeed to 0

    wait()
    local Player = game.Players.LocalPlayer
    local Char = Player.Character
    local Cam = game.Workspace.CurrentCamera
    local ICover = Player.PlayerGui.IntroCover -- Replace intro cover with whatever you used for your Gui's Name
   
    Char.Humanoid.WalkSpeed = 0
   
Now that the player cannot move we want to activate the GUI to block all click events.

    wait()
    local Player = game.Players.LocalPlayer
    local Char = Player.Character
    local Cam = game.Workspace.CurrentCamera
    local ICover = Player.PlayerGui.IntroCover -- Replace intro cover with whatever you used for your Gui's Name
   
    Char.Humanoid.WalkSpeed = 0
    ICover.Cover.Visible = true
   
All clicks that are fired will now be handled by that GUI, so nobody can right click and mess with your Intro. Since we have finished all the basic stuff we will now move onto to actual camera stuff. We need to set two things at the same exact time or it will not work correctly, these two things are:

**CoordinateFrame** - *Where your camera will be placed*
**Focus** - *What your camera wil be focusing at (Pointing at)*

For this tutorial I will set the CoordinateFrame to 0,20,0 but you can change the value of the coordinate frame the same way as we are the focus. You just need to do a lot more positioning to get it right. Lets start programming this son of a gun, we will first determine how many points we have. For this example I will settle with three random points.

5,1,22
55,44,2
12,34,1

For this part we will only be setting the Focus, as said above you can edit the coordinate frame to have a better looking Intro. We have three points so that means we will be using three for loops. You will be using as many for loops as you have points. Since this is a basic tutorial we will be leaving it at that, there are ways to make it more efficient but it is a bit more advanced. Lets get with it:
   
    wait()
    local Player = game.Players.LocalPlayer
    local Char = Player.Character
    local Cam = game.Workspace.CurrentCamera
    local ICover = Player.PlayerGui.IntroCover -- Replace intro cover with whatever you used for your Gui's Name
   
    Char.Humanoid.WalkSpeed = 0
    ICover.Cover.Visible = true
   
    Cam.CoordinateFrame = CFrame.new(0,20,0)
    Cam.Focus = CFrame.new(0,0,0) -- Will fix this in the next steps
   
    for pos=0,1,.01 do -- First Position
    end
    wait(1) -- The time it takes before the next point shows.
    for pos=0,1,.01 do -- Second Position
    end
    wait(1)
    for pos=0,1,.01 do -- Third Position
    end
   
We now have established the basic outlines for our intro, we will be multiplying CFrame values to get a smooth animation. As you can see in our for loop we have the range set from 0-1 and the interval set to .01, the interval will control how long the animation takes. If your animation does not get to its destination in time just modify the range. The higher the number the longer it will take. Also, to make it smooth and not jumpy we compose two CFrames after the first for loop. This is so is smoothly goes from one position to another.

    wait()
    local Player = game.Players.LocalPlayer
    local Char = Player.Character
    local Cam = game.Workspace.CurrentCamera
    local ICover = Player.PlayerGui.IntroCover -- Replace intro cover with whatever you used for your Gui's Name
   
    Char.Humanoid.WalkSpeed = 0
    ICover.Cover.Visible = true
   
    Cam.CoordinateFrame = CFrame.new(0,20,0)
    Cam.CameraType = Enum.CameraType.Fixed -- We added this so we can manipulate the camera freely.
   
    for pos=0,1,.01 do -- First Position and figure
        Cam.Focus = CFrame.new(5*pos,1*pos,22*pos)
        wait() -- We add this so the animation is smooth and does not finish instantly.
    end
    wait(1) -- The time it takes before the next point shows.
    for pos=0,1,.01 do -- Second Position
        Cam.Focus = CFrame.new(5,1,22)*CFrame.new(55*pos,44*pos,2*pos) -- We removed the *pos from the first one because we already animated that, The first CFrame value is where the camera last left off.
        wait()
    end
    wait(1)
    for pos=0,1,.01 do -- Third Position
        Cam.Focus = CFrame.new(55,44,2)*CFrame.new(12*pos,34*pos,1*pos)
        wait()
    end
   
    ICover.Cover.Visible = false
    Cam.CameraType = Enum.CameraType.Follow -- I assume this is what it originally is.
    Char.Humanoid.WalkSpeed = 16
   
You can reset the cameras position if you like, but the main thing to change is the CameraType. Now we are just reseting the values to the default settings and we are good to go.

There we have it, a fully functioning camera cutscene. I will have some notes below if you want to expand it...


## Notes ##

 - You might want to check where the camera is pointing at using some sort of marker, just to make sure it is pointing in the direction you want.
 - When composing the before and after CFrames you might have to change the Y Value to a negative or positive for it to point correctly.
 - If you want to position the coordinateframe like we did the focus, use the same method. You will just have to get three more points.



Ask Questions Below!!

No comments:

Post a Comment