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

Rotate a part so both extremities connect two specific points?

I have two vector3 points, and there is a part exactly positionned on the midpoint between them. The part is as long as the distance between the two points. How do I rotate it so it connects the two points?

So far what I've got

brick.Size=Vector3.new((tab[i]-tab[i+1]).magnitude,.2,0)
brick.CFrame=CFrame.new(.5*tab[i+1]+.5*tab[i])*CFrame.Angles(0,math.pi,0) --Gotta change that math.pi for something appropriate

1 answer

✓ Accepted answer

So, you have the Part positioned correctly, although admittedly with a method that hurts the look at. Anyways, you don't need to mess around with CFrame.Angles. A much easier method is to use the CFrame.new(position, lookAt) constructor.

Since the Part's already in the correct position, don't change that. But we can edit the second argument so that it will point towards the brick of your choice.

part.CFrame = CFrame.new(part.Position, workspace.Brick.Position) --Makes it face towards Brick.

4 comments

0

Why does my positionning method hurts to look at? xd

0

It's pretty complicated, when you could just get the average: (point1 + point2) / 2. Also not sure what 'tab' or 'i' is.

0

tab is the table in which the points are stored, and .5point1+.5point2 is the same thing. Also its 180 degrees facing the wrong way, how to I rotate it 180 degrees?

0

CFrame.new(position, lookAt) makes the front face of the object look at the second argument. Just change the second argument or switch the object's dimensions.

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