Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How and when to use magnitude?

Asked by 4 years ago

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

2 answers

Log in to vote
0
Answered by 4 years ago

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
Ad
Log in to vote
0
Answered by 4 years ago

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
0
How would I say if the player is close enough to the brick the brick appears? PrismaticFruits 842 — 4y
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 Luka_Gaming07 534 — 4y

Answer this question