How To Increase and Decrease Vector3 Values: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Pspdude40
(Page Creation)
 
>Pspdude40
(Page Creation)
(No difference)

Revision as of 17:16, 31 July 2008


Intro and Notes

Intro

So, you do know how to increase and decrease Vector3 Values, right? Now, this tutorial will tell you how to increase and dcrease them! This will be quite a benefit to your scripts, and will make them more popular if you have them!

Notes

Please note that you need to be an experienced scripter in order to understand this tutorial. If you aren't, then you won't understand anything. View one of the basic tutorials before reading on. If you're experienced, contuine reading on if you want to do it someday!


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 Vaules!

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. I'll try to make it as detailed as possible. 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

Good! So far, so good! We currently have 2 lines done! 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

Altough 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

But it's not over yet. 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. If it was exactly the same, then what's the point?

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!


Conclusion

You just added and subtracted Vector3 Values! What's next? Well, I don't know. Go to another tutorial if you want to!