generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Rotating parts relative to base

Previous Thread :: Next Thread 
ZizZazZuz is not online. 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 is not online. 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
BlueTaslem is not online. BlueTaslem
Joined: 11 May 2008
Total Posts: 11060
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 is not online. 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 is not online. 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
BlueTaslem is not online. BlueTaslem
Joined: 11 May 2008
Total Posts: 11060
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 is not online. 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 is not online. ZizZazZuz
Joined: 16 Jun 2008
Total Posts: 2743
03 May 2013 11:11 AM
Uh oh, he's offline.
Report Abuse
BlueTaslem is not online. BlueTaslem
Joined: 11 May 2008
Total Posts: 11060
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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image