ZizZazZuz
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 2743 |
|
|
| 02 May 2013 09:24 PM |
I have a model that I want rotated in random multiples of 90 degrees, from 0 to 3 times. Here is the situation:
-I have "model", which should be the reference for the relative positions of the parts -And I have "clone", which is the clone of the model, and needs its parts rotated. -Each part in the model is named uniquely, and can be related using :FindFirstChild.
I'll be working on this as well, I'll let you know if I find a solution. |
|
|
| Report Abuse |
|
|
ZizZazZuz
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 2743 |
|
|
| 03 May 2013 10:10 AM |
| I'm still working on it. I probably need to do something with lookVector. If you need any more details, just ask. |
|
|
| Report Abuse |
|
|
|
| 03 May 2013 10:17 AM |
| If you transform all of the CFrames of the parts to the object space of one of them (using CFrame:ToObjectSpace), then change that part's CFrame, you can convert all of the object space CFrames back to worldspace (CFrame:ToWorldSpace) and have the model repositioned / rotated so that the one part is where you tell it to be. |
|
|
| Report Abuse |
|
|
ZizZazZuz
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 2743 |
|
|
| 03 May 2013 10:28 AM |
So if I had part A, and I said:
A.CFrame:ToObjectSpace(base.CFrame)
Then I moved base to:
base.CFrame = plat.CFrame * CFrame.angles(0, math.pi/2, 0) + Vector3.new(0, plat.Size.y/2 + base.Size.y/2) --plat is my shorthand for platform, btw
Then that would rotate part A with the base? Or are you talking about something else? |
|
|
| Report Abuse |
|
|
ZizZazZuz
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 2743 |
|
|
| 03 May 2013 10:29 AM |
| Oops, forgot the z axis in my example. Oh well. |
|
|
| Report Abuse |
|
|
|
| 03 May 2013 10:37 AM |
Okay, so B is positioned relative to A.
rel = A.CFrame:toObjectSpace(B.CFrame);
--move a
A.CFrame = CFrame.new(); --whatever
B.CFrame = A.CFrame:toWorldSpace(rel);
Now B will be in the same relative position to A as it was before, but A will be where you told it to be. |
|
|
| Report Abuse |
|
|
ZizZazZuz
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 2743 |
|
|
| 03 May 2013 10:44 AM |
| Holy moley, that's a whole lot easier than the six lines I had to use! Does that cover rotation too? So if I rotate A, will B rotate around it? |
|
|
| Report Abuse |
|
|
ZizZazZuz
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 2743 |
|
| |
|
|
| 03 May 2013 11:46 AM |
Yes. "rel" will encode the complete description of the CFrame. In general, a:toWorldSpace(a:toObjectSpace(x)) == x (approximately, that probably won't be true most of the time because of rounding errors, but it will *look* true)
Which is part of the reason why you can know that it uses rotation. |
|
|
| Report Abuse |
|
|
ZizZazZuz
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 2743 |
|
|
| 03 May 2013 11:57 AM |
:'-)
Beautiful. All my problems are solved! Now lemme test it. :D |
|
|
| Report Abuse |
|
|