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 » Scripters
Home Search
 

Re: How CFrame.Angles and CFrame.fromAxisAngle works (guide)

Previous Thread :: Next Thread 
sonihi is not online. sonihi
Joined: 27 Jun 2009
Total Posts: 3655
06 Aug 2017 07:32 AM
1st off you must understand what a CFrame is. It has a position and then something I like to think about as a coordinate grid. This coordinate grid is made of 3 Vectors, which correspond to the X-,Y-,and Z-Axis.
This may be a helpful guide: http://devforum.roblox.com/t/how-to-think-about-cframes/11743/24

Now what does CFrame.Angles do? Well if you do Part.CFrame*CFrame.Angles(math.rad(xRot),0,0) it turns around the Part's CFrame's X-Axis by xRot degrees. You may want to know what CFrame.Angles with multiple numbers does, so something like this:
Part.CFrame*CFrame.Angles(math.rad(xRot),math.rad(yRot),math.rad(zRot))

This is equivalent too (math.rad replaced with rad and CFrame.Angles replaced with Angles):

Part.CFrame*Angles(rad(xRot),0,0)*Angles(rad(yRot),0,0)*Angles(rad(zRot),0,0)

So this means we first rotate around the X-Axis, then the Y-Axis and then the Z-Axis (NOTE: The order matters).

But you may also see something like this: Angles(0,rad(yRot),0)*Part.CFrame
This basically rotates the Part's CFrame around the world's Y-Axis, including it's position. To not rotate the position you'd need to do something like this: Angles(0,rad(yRot),0)*(Part.CFrame-Part.CFrame.p)+Part.CFrame.p (NOTE: Part.CFrame.p is the position of the Part).

Now this is good so far but what if we wan't to rotate around any axis?
Here is where CFrame.fromAxisAngle come into play. It takes two values/arguments: A vector (the axis we'll be rotating around) and an Angle (how much we'll rotate around this axis).

So we'll go back to our Part and see how to rotate it around around an axis (described in world coordinates), let's say Vector3.new(1,1,1).
So we do CFrame.fromAxisAngle(Vector3.new(1,1,1),math.rad(20))*Part.CFrame. This rotates the part around the Axis Vector3.new(1,1,1) by 20 degrees but it also rotates the position. To not change the position we'll have to do this:
CFrame.fromAxisAngle(Vector3.new(1,1,1),math.rad(20)) * (Part.CFrame-Part.CFrame.p) + Part.CFrame.p


-----The End----

Report Abuse
sonihi is not online. sonihi
Joined: 27 Jun 2009
Total Posts: 3655
06 Aug 2017 07:58 AM
Questions?
Report Abuse
Apochroseis is not online. Apochroseis
Joined: 29 May 2015
Total Posts: 1021
06 Aug 2017 08:08 AM
thanks!


Report Abuse
sonihi is not online. sonihi
Joined: 27 Jun 2009
Total Posts: 3655
10 Aug 2017 10:23 AM
bamp
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
10 Aug 2017 10:29 AM
"It has a position and then something I like to think about as a coordinate grid. This coordinate grid is made of 3 Vectors, which correspond to the X-,Y-,and Z-Axis."
All hail Sonihi, the new cringelord.


Report Abuse
sonihi is not online. sonihi
Joined: 27 Jun 2009
Total Posts: 3655
10 Aug 2017 10:37 AM
Thanks Jarod, proud of taking your throne
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
10 Aug 2017 10:39 AM
I was bucking for the job, but you beat me.


Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
10 Aug 2017 10:40 AM
Also, that was an epic comeback.


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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