# Finding 2 Parts That Make Straightest Line

Hello, I asked this on a previous post, but unfortunately the solution I got ended up not working with my system. But anyways If I have multiple sets of 2 parts each. And I have to see which 2 parts both form the straightest line basically, what would I do? I tried to use Dot(), but what if the parts can be rotated 180 degrees so it’s facing the other side, then it fully changed what Dot() will return. Any ideas on what else to use or am I using Dot() incorrectly for my situation. Below is some examples of what I mean the green parts showing which set shows the biggest angle and the red parts showing the smaller angles. NOTE: The parts lengths can be resized so checking length apart won’t help.

1 Like

???, I am referencing scripting, this has nothing to do with building. I just have an image with parts.

show me the scipt, so i can see what you´ve done wrong!

1 Like

I’m not looking for scripting help, I’m looking for ideas how to script something. Example: Just find so and so dots and get the lookvector of them. Keep in mind, I’m not looking for code.

try reading, posts like abt scripting and there might give you some ideas about these stuf or look vids!!

1 Like

Use math.abs() on the :Dot() result, and choose the closest one to 1

1 Like

I have done all that. I have asked many times for help on scripting. I think I know what I’m doing here, and I think I’m in the right category. Thank you for trying to help.

1 Like

Alright, letme try your solution. I will get back to you.

1 Like

You positive it’s supposed to be closest one to 1, I keep trying to get that result, but everytime it always seems to be the furthest from 1?

Yes, try printing:

Vector3.new(0,0,1):Dot(Vector3.new(0,0,1)) -- prints 1
Vector3.new(0,0,1):Dot(Vector3.new(1,0,0)) -- prints 0

As you can see, 2 parallel vectors print 1, and
2 perpendicular vectors print 0

Vector3.new(0,0,1):Dot(Vector3.new(0,0,-1)) -- prints -1

Opposite vectors print -1, which is why we use math.abs() to get rid of the negative sign

Have you tried comparing the rotation of 2 parts? I would compare the absolute values of the rotations to see which rotation is the closest to one’s part

Definitely didn’t originally just get the position of the part instead of the directional vector between the front and back end. Whoops. This solution works, thank you very much. Your post has been marked as the solution!

1 Like