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

How do you figure you how far a wall or part?

So you have a part and imagine there is is a uneven surrounding this is what i mean:

|				|  
    |				|  
|				   |  
  |				   |
  |		[Part]            |    
|				  |  

is there a way to figure out how far the wall is from the part?

i don't want to change the size of another part to measure the size!

this is what i mean with change the size of the part:

|				|  
    |				|  
|				   |  
  |				   |
  | <=====[Part]=== > |    
|				  |  

<= is a part but a part that is changing the size!

as you can see Left is more than right so we can assume its left!.

but is it possible to to estimate how far a wall/Part is with out using the "Change Size method"?

3 comments

1

If you're talking about the distance between the wall and the part, that's magnitude. If you're talking about the mid way point, that's the magnitude divided by 2.

0

can you provide the code please! :)

1

(position1 - position2).Magnitude

1 answer

✓ Accepted answer

Like the person commented in the comments, Magnitude is what you need.

Magnitude is the length of a vector

Example

local leftWall  = youReferenceHereTheLeftWall
local rightWall = youReferenceHereTheRightWall
local part = referenceToPart

local leftDistance = (leftWall.Position - part.Position).Magnitude
local rightDistance = (rightWall.Position - part.Position).Magnitude
print("The part is ", leftDistance, " studs away from left wall and ", rightDistance, " studs away from right wall.")

5 comments

1

bruh. did you forget that part.Position returns the middle point of the part which means you would have to do part.Position+(part.Size.Y/2)

1

depending on the position X/2 or Y/2

1

no, but i cant guess its rotation, this is just an example

1

and your above would only work if they ahve the similar rotation

0

Thankyou @VerdommeMan

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