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

Brick rotation help?

Asked by 8 years ago

I'm working on something that involves two bricks. If one of the bricks rotate, then the other brick needs to stay the same distance away but rotate around it at the same time. Is there any way to script that?

0
Could you please expand apon what you mean? I'm not sure what you mean. ProtectedMethod 105 — 8y
0
Do you mean welding one brick to another? Or do you mean an Earth - Moon orbit where bot parts are individually moving? TheDeadlyPanther 2460 — 8y
0
I'll elaborate. There's two bricks. The side brick needs to maintain it's distance and rotation while remaining straight in accordance to the rotation of the first brick. For example, if the brick was 2 studs away from the right side, I want it to maintain that distance and straight rotation when the first brick gets rotated. TealTeam 40 — 8y
0
So you don't want the side brick to face in the same direction as the main brick? TheDeadlyPanther 2460 — 8y
View all comments (4 more)
0
No, I want it to have the same rotation as the main brick, but maintain the two stud ratio no matter what the rotation of the first brick is. TealTeam 40 — 8y
0
The answer is welding. I don't have access to studio now, but I may have access in a couple of hours, so if you could wait that long? TheDeadlyPanther 2460 — 8y
0
I know how to weld, but this needs to be a scripting thing. Welding would absolutely be detrimental to what i'm doing with it. TealTeam 40 — 8y
0
Oh, damn. I can't do it then :/ TheDeadlyPanther 2460 — 8y

1 answer

Log in to vote
3
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

If you want to preserve the relative orientation of another part to one that is rotating, then take two parts a and b; a is rotating. Get the new CFrame for a:

local new=a.CFrame*CFrame.Angles(0,math.pi/8,0)

set b's new CFrame relative to the change in a's CFrame:

b.CFrame=new*a.CFrame:inverse()*b.CFrame

set a's CFrame

a.CFrame=new
0
Thank you, I appreciate it very much. TealTeam 40 — 8y
0
Alternatively, local relative = a.CFrame:toObjectSpace(b) a.CFrame = a.CFrame*CFrame.Angles(0, math.pi/8, 0) b.CFrame = a.CFrame:toWorldSpace(relative) adark 5487 — 8y
Ad

Answer this question