How To Increase and Decrease Vector3 Values: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Mindraker
Yes, we all 'have to be experienced scripters' to understand 'your complicated tutorial'.
>Mindraker
Yes, we all 'have to be experienced scripters' to understand 'your complicated tutorial'.
(No difference)

Revision as of 21:18, 23 August 2008

Introduction

This tutorial will tell you how to increase and decrease Vector3 values. This will be quite a benefit to your scripts, and will make them more popular if you have them.

Adding Vector3 Values

This will show you how to add or subtract 3 vector3 numbers. The stuff below will be quite interesting to you if you want to add or subtract Vector3 Values.

First, insert a Vector3Value. Once you have that done, change the value to 15, 15, 15.

Then, insert a script. Make the script's parent the Vector3Value.

Scripting

Once those parts are done, open the script. First, we need to identify the value we want to change. So put in this.

local value = {script.Parent.Value}

The value is whatever value you put. Next, we need to put an i = 1 part. I don't know why we have to do this, but we have to.

local i = 1

Let's look at our progress:

local value = {script.Parent.Value}
local i = 1

Since we have those 2 lines down, we now can tamper into the x, y, and z of the Vector3 Value. Let's say we want to add 5 to the value. Put in these lines...

local x = value[i].x
local y = value[i].y
local z = value[i].z

Although we have the 3 seperate numbers, we still haven't added or subtracted them yet. In order to do that, you just have to add and subtract it like you do with regular numbers.

x = x + 5
y = y + 5
z = z + 5

Now we have the new x, y, and z. Let's take a look at what we have so far:

local value = {script.Parent.Value}
local i = 1
local x = value[i].x
local y = value[i].y
local z = value[i].z
x = x + 5
y = y + 5
z = z + 5

The 3 single values have changed, but not the Vector3Value. In order to do that, we need to insert this line:

script.Parent.Value = Vector3.new(x,y,z)

Now the value has changed. But how will we know? We just need to put in another line. Make sure you have output up first:

print(script.Parent.Value)

The script is complete! Let's just look at the finished script:

local value = {script.Parent.Value}
local i = 1
local x = value[i].x
local y = value[i].y
local z = value[i].z
x = x + 5
y = y + 5
z = z + 5
script.Parent.Value = Vector3.new(x,y,z)
print(script.Parent.Value)

Output should say 20, 20, 20. You're done!


Subtracting Vector3 Values

We've added them, but we now subtract them! Subtracting them is just like adding them, only we edit 3 lines.

x = x - 5
y = y - 5
z = z - 5

Now, let's take a look at that edit in the full script:

local value = {script.Parent.Value}
local i = 1
local x = value[i].x
local y = value[i].y
local z = value[i].z
x = x - 5
y = y - 5
z = z - 5
script.Parent.Value = Vector3.new(x,y,z)
print(script.Parent.Value)

Output should say 10, 10, 10. You're done with subtracting them!