|
| 02 Apr 2013 08:33 PM |
When I multiply a CFrame.Angles value onto a cframe value multiple times and try to return it to normal, it is never the same. Here is an example.
local cframe = someCFrameValue
cframe = cframe * CFrame.Angles(math.pi,0,0) cframe = cframe * CFrame.Angles(0,math.pi,0)
wait(1)
cframe = cframe * CFrame.Angles(-math.pi,0,0) cframe = cframe * CFrame.Angles(0,-math.pi,0)
You would think the cframe value would be the same as it was in the beginning right? Wrong, does anybody have any ideas why this doesn't go back to normal? Is their a better way to rotate CFrame values? |
|
|
| Report Abuse |
|
|
sssnow
|
  |
| Joined: 22 Nov 2010 |
| Total Posts: 2131 |
|
|
| 02 Apr 2013 08:39 PM |
Maybe this would help a tad: http://wiki.roblox.com/index.php/CFrame |
|
|
| Report Abuse |
|
|
|
| 02 Apr 2013 08:41 PM |
| Believe me when I say I am very familiar with that page, and I can't find anything useful to me there for this situation. |
|
|
| Report Abuse |
|
|
killjoy37
|
  |
| Joined: 27 Aug 2008 |
| Total Posts: 2821 |
|
|
| 02 Apr 2013 08:44 PM |
| I have the same problem as you, it makes no sense. When I am rotating, I use Cframe.fromEulerAnglesXYZ and that always works right. I never use .Angles. Make sure its in radians though |
|
|
| Report Abuse |
|
|
killjoy37
|
  |
| Joined: 27 Aug 2008 |
| Total Posts: 2821 |
|
|
| 02 Apr 2013 08:45 PM |
| Before doing that, try doing them in the exact opposite order, like a,b,-b,a rather than a,b,-a,-b and see if that works. |
|
|
| Report Abuse |
|
|
|
| 02 Apr 2013 08:47 PM |
| That does work killjoy, but that doesn't help me. Also fromEulerAnglesXYZ is the same as Angles, but thanks for trying to help. Any other ideas? |
|
|
| Report Abuse |
|
|
killjoy37
|
  |
| Joined: 27 Aug 2008 |
| Total Posts: 2821 |
|
|
| 02 Apr 2013 08:53 PM |
| mm. Sorry. I think what happens is it rotates based on the parts current rotation rather than a general rotation, like, the parts axes are rotated with it while the place axes stay constant. So I guess you would have to do some major trig to figure out where that axis is. I'm sure there is a roblox function for it though. Maybe that from object to world coordinates thing would work here? |
|
|
| Report Abuse |
|
|
|
| 02 Apr 2013 08:57 PM |
| How do I get the roll,pitch,and yaw of an object? I believe toEularAnglesXYZ is unaccurate. |
|
|
| Report Abuse |
|
|
killjoy37
|
  |
| Joined: 27 Aug 2008 |
| Total Posts: 2821 |
|
|
| 02 Apr 2013 09:04 PM |
To be honest, I've never heard of those terms. I just know that I'm unskilled with CFrame, and that fromEulerAnglesXYZ was always my best friend for my CFrame projects. :) But do you agree with what I was saying about how the objects axes change and it bases the angles off of those new axes? |
|
|
| Report Abuse |
|
|
|
| 02 Apr 2013 09:05 PM |
| Hmm, I am unfamiliar with object vs world space. I will look into it and hopefully it will help me, I understand what you are suggesting, and it makes sense. |
|
|
| Report Abuse |
|
|
|
| 02 Apr 2013 09:08 PM |
Basically you have to keep the order in which you rotated the CFrame. So if you rotate it like:
cf = cframe angle1 = angle angle2 = angle
cf = cf*angle1*angle2
You have to rotate it like:
cf = cf*angle2:inverse()*angle1:inverse()
You can almost think of it like wrapping the CFrame and unwrapping it. You rotated it out of order which is why you got weird results. Btw when you're trying to get the inverse of a cfame you can just use cframe:inverse() (as shown above). With what you were doing CFrame.Angles(-math.pi,0,0) would have worked anyways but just changing the numbers to negative won't always give you the inverse |
|
|
| Report Abuse |
|
|
killjoy37
|
  |
| Joined: 27 Aug 2008 |
| Total Posts: 2821 |
|
|
| 02 Apr 2013 09:10 PM |
| Could you give an example of where it wouldn't? |
|
|
| Report Abuse |
|
|
|
| 02 Apr 2013 09:12 PM |
I am making a helicopter which uses BodyGyro to rotate the helicopter to make it look better, so I will never know which order the player will rotate the helicopter.
@killjoy are you talking to me? where what wouldn't what? |
|
|
| Report Abuse |
|
|
killjoy37
|
  |
| Joined: 27 Aug 2008 |
| Total Posts: 2821 |
|
|
| 02 Apr 2013 09:14 PM |
| Sorry, I was talking to stygianblade. For your helicopter problem, why do you need to reset it back where it started? |
|
|
| Report Abuse |
|
|
|
| 02 Apr 2013 09:18 PM |
| When the player pushes the "d" key, it rolls right, and if they were to continue pushing "d" then press "w", it would need to roll forward as well as staying to the right, and when they released their fingers, I would want it to roll back to a neutral position. |
|
|
| Report Abuse |
|
|
|
| 02 Apr 2013 09:23 PM |
@kill print(CFrame.Angles(1,1,1):inverse() == CFrame.new(-1,-1,-1))
@roy Can't help you with that ;P I always manually CFrame objects for animations and what not so I've never worked with body objects |
|
|
| Report Abuse |
|
|
killjoy37
|
  |
| Joined: 27 Aug 2008 |
| Total Posts: 2821 |
|
|
| 02 Apr 2013 09:24 PM |
| But not all the way back, right? I mean just a little bit to the left and up (or down, opposite of what w does), I would still try EulerAnglesXYZ because I'm almost positive it will work. So if it matters what direction you put those lines in when you a returning it to its original position, then the order you put them in would matter, meaning d then w would result in a different rotation than w then d, which I don't think you'd want |
|
|
| Report Abuse |
|
|
killjoy37
|
  |
| Joined: 27 Aug 2008 |
| Total Posts: 2821 |
|
|
| 02 Apr 2013 09:26 PM |
| @blade ...but 1 * -1 = -1. I mean an example where inverse does not multiply the value by -1 (or achieve the same result as doing that) |
|
|
| Report Abuse |
|
|
|
| 02 Apr 2013 09:26 PM |
"When the player pushes the "d" key, it rolls right, and if they were to continue pushing "d" then press "w", it would need to roll forward as well as staying to the right, and when they released their fingers, I would want it to roll back to a neutral position."
Well why don't you just keep track of their key presses and apply the oppisite rotation once they let go |
|
|
| Report Abuse |
|
|
killjoy37
|
  |
| Joined: 27 Aug 2008 |
| Total Posts: 2821 |
|
|
| 02 Apr 2013 09:30 PM |
or do what blade said if it does matter (to you) what order they press them in, do like w = false d = false a = false s = false then if they hit a key, make it true and the rest false, and if they release a key, make it false. Wait a sec, they won't release at the same time, which is essentially like releasing one and keeping the other held down, so what do you want to happen in that case is the question that you need to ask |
|
|
| Report Abuse |
|
|
|
| 02 Apr 2013 09:30 PM |
@stygianblade
That would probably work but it doesn't matter anymore because I figured it out! I made my own custom function and it works like a charm in any order I put it in! Thanks for the help anyways guys! |
|
|
| Report Abuse |
|
|
killjoy37
|
  |
| Joined: 27 Aug 2008 |
| Total Posts: 2821 |
|
|
| 02 Apr 2013 09:33 PM |
| If any other problems arise, come back to this thread, I'm sure you'll make some breakthrough just by going through our different thought processes. Glad you figured it out though! Always a nice feeling. I am interested in your script if you don't mind. If you don't want to show the whole world I don't blame you. |
|
|
| Report Abuse |
|
|
|
| 02 Apr 2013 09:35 PM |
Yeah I would rather not show the whole script but I will show the part that concerns this problem :)
local scale = 7
function rotate(cframe,x,y,z) local x1,y1,z1 = cframe:toEulerAnglesXYZ() local pos = cframe.p local posCFrame = CFrame.new(pos) if x ~= 0 then return posCFrame * CFrame.Angles(x+x1,y1,z1) elseif y ~= 0 then return posCFrame * CFrame.Angles(x1,y+y1,z1) elseif z ~= 0 then return posCFrame * CFrame.Angles(x1,y1,z+z1) end end
bGyro.cframe = rotate(bGyro.cframe,-math.pi/scale,0,0) |
|
|
| Report Abuse |
|
|
killjoy37
|
  |
| Joined: 27 Aug 2008 |
| Total Posts: 2821 |
|
|
| 02 Apr 2013 09:38 PM |
| Well, that's beyond the scope of my knowledge. Maybe you can explain it to me sometime. I gotta go to bed now, though, so I guess I'll talk to you later. |
|
|
| Report Abuse |
|
|
|
| 02 Apr 2013 09:39 PM |
| Haha okay, PM me when you want to learn about it, I would be happy to share my knowledge :3 |
|
|
| Report Abuse |
|
|