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

Rotate a part so both extremities connect two specific points?

Asked by
KoreanBBQ 301 Moderation Voter
8 years ago

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

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
8 years ago

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.
0
Why does my positionning method hurts to look at? xd KoreanBBQ 301 — 8y
0
It's pretty complicated, when you could just get the average: (point1 + point2) / 2. Also not sure what 'tab' or 'i' is. Perci1 4988 — 8y
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? KoreanBBQ 301 — 8y
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. Perci1 4988 — 8y
Ad

Answer this question