ROBLOX How To's

From Legacy Roblox Wiki
Revision as of 13:48, 5 June 2008 by >Dingdong272 (Tutorials on things not already documented in the Wiki.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Introduction

Welcome to the ROBLOX How To's page. This page is for people who want to learn how to do some serious things on building and scripting. If you're here to learn how to put teams in your place, try the Tutorials section.


Building

This is where all the major building topics are going to be stored.

Welds

No, not the kind where you take the weld tool and put two bricks together. This is serious welding, used for multi-handled weapons (such as xLEGOx's NXT Gen Weapons), and much, much more. Now, here's a bit on welds:

Prerequisite: Know how to use a basic cframe (CFrame.new(#, #, #)), and how to index and change the properties of an object, using a script.

Part I : Welds What are welds? They are an object, that hold thier parent part, and another part, in position relative to eachother, for example, hold one part 2 units to the right of the other brick. They can be used in places where parts need to be held together ar odd angles, but still be able to mov, such as for a vehicle.

Basic structure: The basic structure of a weld is as follows. The weld object is placed inside of a part, and a property is set, to determine another part wich should be welded to the original part. Then two CFrames, the C0 and the C1, tell the weld how the parts should be placed.

Part0: This property of a weld is an Object, it must allways be set to the part the weld is in for the weld to work


Part1: This property of a weld is an object and tells is which part it should be attaching it's parent to

C0: the C0 of a weld, determines how the [offset point] should be attached to the Part0

C1: the C1 of a weld, determines how the Part1 should be attached to the [offest point]

Setting the values: Figuring out what to set the C0 and C1 to is a bit finnicky, but one you get good at it it can go quite quickly. For Welds, you dont have to worry about the C1, it's automaticaly set to a "unit" or unrotated CFrame, you only have to deal with C1 when working with motors, so ignore it for now. The C0 will tell the weld how it should attack the other part, eg.

[weld].C0 = CFrame.new(0, 2, 0)

This tells the weld that it should hold the part1 in a position 2 studs above the part0, simple eh?

Rotating the CFrame: Now it gets a bit tricky. To rotate the CFrame you must use the following command, which is case sensitive... CFrame.fromEulerAnglesXYZ(#, #, #)

which is used in the following way... [weld].C0 = CFrame.new(0, 2, 0)*CFrame.fromEulerAnglesXYZ(0, math.pi, 0)

this tells the weld to attach the part1, two studs above the part0 AND rotate the part1 by 180 degrees relative to the part0

math.pi?? Yes you use math.pi, as the number to rotate by, use it in the following fashion :

math.pi = 1/2 of a turn math.pi/2 = 1/4 of a turn math.pi/4 = 1/8 of a turn etc..

Putting it all together : Well, not that you know how to use the basics of a weld, here's how you put it all together. Here's an exapmle, which if you understood all the previous stuff should be enough for you to get it =P

lets say that this is in a script, in a vehicle:


pln = script.Parent

local w = Instance.new("Weld") w.Parent = pln.Engine w.Part0 = pln.Engine --> part0 has to be the parent w.Part1 = pln.Wing1 w.C0 = CFrame.new(0, 0, 6)*CFrame.new(0, -math.pi/5, 0)


Scripting

This is where all the major scripting topics are going to be stored.

Global Functions

Have you ever wondered how things like :Remove() and :Clone() always work, even though you've never indexed it? Here's how:

If you know how to use the _G[] (global) command, this might come more easily to you than others. This is basically how a global command works:

_G["Bob"] = game.Workspace.Bob

If you're in a ScriptBuilder, you can exit that script and open a new one. Put this in it:

Bob.Torso:Remove()

run that script, and your torso gets removed! Why? Because the _G[] (global) command makes "Bob" availible in every script. Now, to get a global function:

_G["Lazer"] = function(person) person.Torso:Remove() end

Now exit that, and do this:

Lazer(game.Workspace.Bob)

If your character's name is, "Bob," you should have your torso removed.

Custom Objects

A custom object is something that you create that has properties like the other ROBLOX objects, such as game.Workspace.Brick.Transparency

Here's how:

your data type here will be a "Vector2"

Vector2 = {} --this decalres and object of the class "Vector2"(yes, it is a table as well)

function Vector2:new(one, two) --the function that we will use to create new objects of this class newTB = {x, y} --this makes our new object with the properties, which you set as objects in the table newTB.x = one --set the value to the one called in the argument newTB.y = two return newTB end

--now we can call a new object of the class as such...

a = Vector2.new(7, 8)

print(a.x) --> 7

print(a.y) --> 8

a.x = 10

print(a.x) --> 10


Quite simple isnt it?

how can you add member (methods, deemed properly) functions to yopur object though?


function Vector2:new(one, two) newTB = {x, y} newTB.x = one newTB.y = two

function newTB.reset() newTB.x = 0 newTB.y = 0 end

return newTB end


a = Vector2.new(5, 8)

print(a.x) --> 5 print(a.y) --> 8

a:reset()

print(a.x) --> 0 print(a.y) --> 0


Changing The Camera's View

People have wondered how to do this for ages. And, there are many more properties than just "CameraSubject" in a Camera object. To change the camera's view:

You can use one of two things to change the camera's view....

1) [camera].Focus = CFrame.new(?)

2) [camera].Coordinateframe = CFrame.new(?)

Now you can finally make the ever elusive: cut scenes!

Terrain Generation

It's a really good question. How do you do it? This explains how, and it is sort of complicated, so don't freak out if you don't get it.

Terrain Generation:

Fisrt, the way the terrain looks, it based off of a number of points, either set randomly or by the user. The terrain genarator will try to drag the land upwards or downwards based on the hight and position of these points, which I will refer to as "nodes".

When generating the terrain, the terrain generator will go through every part, in the list of parts being worked with, and do the following routine for it...

{ for each of the nodes do the following... 1) check the distance from the node to the current part.

2) make a modifier, based on the distance, such as the modifier being the distance/10.

3) then if the part is below the node, subtract the modifier from it's vertical size, or if it's above add to it. }

And it's that simple!, the farther away the point is from the nodes(s), the less it will be changed, resualting in a perfectly sloped surface.

But, this is just a simplified version, making the landscape's slope curved is a bit more tricky.

giving you a hint it might be something like this...

d = The distance between the node and the part being modifed m = the amount the part will be modified by

m = d^(10/d)

this probably won't make a ver nice thing though, it will curve to sharply, getting it just right is quite finicky.


All credit on information and tutorials goes to Anaminus and xLEGOx.