Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How and when to use magnitude?

I am new to scripting and I don't know how to use magnitude. Could someone help please? Thanks in advance!

2 answers

You can use Magnitudes by adding '.Magnitude' at the end of Vector3 or Vector2 values

Magnitudes can be used when you want to find the length of a Vector3 or Vector2 value, like without the X,Y and Z values of a Vector3 value

For example:

Vector3.new(0,0,0).Magnitude

#What is Magnitude?

Magnitude is basically the Distance of the Vector from the 0, 0 or 0, 0, 0 (Origin) point.

#How can it be used?

It can be used if you want to know the Distance from one Object to another.

##Example:

local Object1 = game.Workspace.ExampleObject1
local Object2 = game.Workspace.ExampleObject2

local Distance = (Object1.Position - Object2.Position).Magnitude
print(Distance)

##Why does this work? This works beause we subtract Object1's Position with Object2's position which gives you another vector that is pointing away from Object2 we then get the Magnitude of the result.

There are brackets around the subtraction because we want the magnitude of the result of the subtraction. Which tells lua

  1. Calculate Object1's position - Object2's position
  2. Get the Magnitude of the result and store it in the Variable Distance

2 comments

0

How would I say if the player is close enough to the brick the brick appears?

0

You can do a if statemet in a while loop and check if the Distance of the Player to the brick is smaller then some amount and then you can set the transparency of the brick

This discussion is preserved as it was. New answers, comments, and votes are closed.