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
|
  |
| Joined: 27 Jun 2009 |
| Total Posts: 3655 |
|
| |
| |
sonihi
|
  |
| Joined: 27 Jun 2009 |
| Total Posts: 3655 |
|
| |
|
| 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
|
  |
| Joined: 27 Jun 2009 |
| Total Posts: 3655 |
|
|
| 10 Aug 2017 10:37 AM |
| Thanks Jarod, proud of taking your throne |
|
|
| Report Abuse |
|
|
| 10 Aug 2017 10:39 AM |
I was bucking for the job, but you beat me.
|
|
|
| Report Abuse |
|
|
| 10 Aug 2017 10:40 AM |
Also, that was an epic comeback.
|
|
|
| Report Abuse |
|