|
| 26 Oct 2016 06:07 PM |
I need to get the rotation of a brick's x axis from 0-360 degrees, how could I do this? brick.Rotation.X only goes from -180 to 135
|
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 26 Oct 2016 06:14 PM |
while wait() do Part.CFrame = Part.CFrame*CFrame.Angles(1,0,0) end
|
|
|
| Report Abuse |
|
|
|
| 26 Oct 2016 06:20 PM |
I wan't to read the rotation, not set it for example if I did brick.Rotation.X I want to get a number from 0-360 not from -180 to 135
|
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 26 Oct 2016 06:28 PM |
Reading -180 is exactly the same thing as reading 540
If you want a more comprehensive readout, just take whatever number you get, and divide it by 360. That'll show you the number of rotations, and in which direction. (+ clockwise, - counterclockwise)
|
|
|
| Report Abuse |
|
|
|
| 26 Oct 2016 06:30 PM |
I don't think you understand, in studio when you spawn a part it's rotation shows (0,0,0), if you rotate it 180 in in the x axis it shows (-180, 0, -180) but I want it to be like (180,0,0) and a full rotation like (360,0,0)
|
|
|
| Report Abuse |
|
|
| |
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 26 Oct 2016 06:52 PM |
You aren't thinking about rotations correctly. In Studio, when you press R to rotate a part, you are not rotating around the X axis, you are rotating around the Y axis.
|
|
|
| Report Abuse |
|
|
|
| 26 Oct 2016 07:37 PM |
Ok I fail at angles
while wait() do local x, y, z = script.Parent.CFrame:toEulerAnglesXYZ() script.Parent.Parent.Part2.CFrame = CFrame.new(0.1, 6.5, 4.8)*CFrame.Angles(0, y, 0)*CFrame.Angles(x, 0, 0) end
I did this and when I rotate script.Parent around Part2 doesn't correspond to it at all, what did I do wrong?
|
|
|
| Report Abuse |
|
|
|
| 26 Oct 2016 07:44 PM |
Wait, you just need the y rotation?
local _, _, _, _, _, Y, _, _, _, _, _, _ = cf:components() local Y = math.asin(Y)
I think o.o, but why not use the built in constructor? CFrame.new(vec1,vec2) |
|
|
| Report Abuse |
|
|
|
| 26 Oct 2016 07:46 PM |
I need both X and Y and I can't use that because it doesn't work with what I'm trying to implement it into
|
|
|
| Report Abuse |
|
|
|
| 26 Oct 2016 07:48 PM |
Which component is the x rotation?
|
|
|
| Report Abuse |
|
|
|
| 26 Oct 2016 07:55 PM |
| I think it's the fourth, don't quote me on that though. |
|
|
| Report Abuse |
|
|
|
| 26 Oct 2016 07:57 PM |
Anyway I did this and it works, but not fully. After I rotate the part more than 90 degrees the other part starts rotating backwards.. Try it for yourself :/
while wait() do local _, _, _, _, _, Y, _, _, _, _, _, _ = script.Parent.CFrame:components() script.Parent.Parent.Part2.CFrame = CFrame.new(0.1, 6.5, 4.8)*CFrame.Angles(0, math.asin(Y), 0) end
|
|
|
| Report Abuse |
|
|
|
| 26 Oct 2016 08:00 PM |
| Asin is locked into the first quadrant I believe. |
|
|
| Report Abuse |
|
|
|
| 26 Oct 2016 08:04 PM |
So what can I do? I need full rotation
|
|
|
| Report Abuse |
|
|
|
| 26 Oct 2016 08:05 PM |
| You could probably calculate the inverse sine yourself, but I have no idea of the formula. |
|
|
| Report Abuse |
|
|
|
| 26 Oct 2016 08:07 PM |
Okay that was a bad explanation.
Inverse sine; I don't know the proper term name for it. But you know what I mean. Calculate it yourself: What I meant was instead of (example) doing math.rad(x) You could do (math.pi/180)*x
I.e. do all of the math on your own to calculate the rotation, which would not lock it into the first quadrant if donr right. |
|
|
| Report Abuse |
|
|
|
| 26 Oct 2016 08:16 PM |
God this is so complicated for something that is meant to be simple. Can you explain a bit further/help me further because I don't really do such advanced math yet
|
|
|
| Report Abuse |
|
|
|
| 26 Oct 2016 08:18 PM |
| I don't know the math for it myself, sorry. There probably is a simple way; ask cntkillme, he helped me understand matrices too. |
|
|
| Report Abuse |
|
|
|
| 26 Oct 2016 08:40 PM |
Bump, cnt doesn't seem to be online now
|
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 26 Oct 2016 10:00 PM |
untested but it worked in my head:
local rdir = script.Parent.CFrame.rightVector local angle = math.atan2(rdir.Z, rdir.X) -- you may have to negate this if angle < 0 then angle = 2*math.pi + angle end |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 26 Oct 2016 10:22 PM |
| technically it would work with lookVector as well but bleh I thought using rightVector was appropriate here |
|
|
| Report Abuse |
|
|
EndOfFile
|
  |
| Joined: 31 May 2015 |
| Total Posts: 16 |
|
|
| 27 Oct 2016 12:47 AM |
May I suggest an approach that I believe to be more simple? The fourth component of a CFrame is the X component of the object-space's X-axis. If we take the inverse cosine of this component, we result in the angle around the Y-axis in the range of 0 <= theta <= pi.
If needed, we can extend this range to cover all quadrants: the tenth component is the X component of the CFrame's Z-axis. This will become positive when the X component of the CFrame's X-axis becomes negative (as both axes are going to be perpendicular).
Essentially this means we can cover the full range in a much more simple manner:
local components = { cframe:components() } local angle = math.acos(components[4])
if components[10] > 0 then -- lies in quadrant 3 or 4 angle = 2*math.pi - angle end
|
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 27 Oct 2016 12:55 AM |
that is much easier to wrap your head around, no doubt in that but i don't think it's going to be accurate if the part is also rotated about the z axes
realistically I don't think there is a perfect solution to this problem and the best solution is if you knew beforehand in what way was the part rotated |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 27 Oct 2016 12:56 AM |
now that i think about it we both did his problem wrong
lmao he wanted the rotation around the x axis not the y axis |
|
|
| Report Abuse |
|
|