Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 11 Aug 2012 08:34 PM |
So I'm trying to get my lovely ship to rotate. Yes?
Ok, so I'm using a BodyGyro....
This is my code to get the right position....
local Direction = VehicleSeat.CFrame local AngleX, AngleY, AngleZ = Direction:toEulerAnglesXYZ() BodyGyro.cframe = CFrame.new(Direction.p) * CFrame.Angles(0, (AngleY % math.rad(360)) + VehicleSeat.TurnSpeed, 0)
Basically, it takes the CFrame of the vehicle seat,r emoves the X and Z directions, and takes the Y angle and adds in the new rotation. I tried applying Modulus to it (But that shouldn't effect it at all, should it, unless it fixes it). The problem is this:
The rotation of the ship gets stuck at -270 and 90. So I only have a 180 turn around. I would like to be able to turn around in any direction I please.
I think it has something to do with the toEulerAnglesXYZ. I haven't learned a whole lot about Euler angles, but I suspect that's the problem.
Anyway, why would this line:
CFrame.new(Direction.p) * CFrame.Angles(0, (AngleY + VehicleSeat.TurnSpeed, 0) -- Same line without Modulus
Stop rotation at -270 and 90? If it isn't a toEulerAngles problem, then what could be wrong.
If it is a toEulerAngles method problem, then how can I neutral/control rocking of the boat (I.E. the X and Z axixes), without using the toEulerAngles method?
Anyway, I suspect there is something wrong with the toEulerAngles, so if someone who is magical at CFrame / Gyros / Angles come over here and help)?
Thanks. |
|
|
| Report Abuse |
|
|
|
| 11 Aug 2012 08:44 PM |
My guess is that fault lies in CFrame.Angles()
I see what you are doing, and I don't think the problem is toEulerAnglesXYZ()
Have you tried
CFrame.fromAxisAngle(v, r) |
|
|
| Report Abuse |
|
|
|
| 11 Aug 2012 08:50 PM |
local Direction = VehicleSeat.CFrame BodyGyro.cframe = Direction.p * CFrame.Angles(0, VehicleSeat.TurnSpeed, 0)
I believe this will serve your propose. Not sure why this works, but yea fault was in how CFrame.Angles() calculated the rotated CFrame |
|
|
| Report Abuse |
|
|
| |
|
Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 12 Aug 2012 10:38 AM |
Ummm.... That doesn't work at all. The VehicleTurnSpeed value is a 0.14 to -0.14 value, so you get about 16 degrees of rotation.
Also, you can't use a Vector3 as a CFrame value, so you have to do...
CFrame.new(Direction.p)
|
|
|
| Report Abuse |
|
|
Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 12 Aug 2012 11:13 AM |
I think I found my problem:
> local X, Y, Z = CFrame.Angles(0, math.rad(80), 0):toEulerAnglesXYZ() print(Y*180/math.pi) --> 79.999990842554
> local X, Y, Z = CFrame.Angles(0, math.rad(95), 0):toEulerAnglesXYZ() print(Y*180/math.pi) --> 85.000017164084
> local X, Y, Z = CFrame.Angles(0, math.rad(100), 0):toEulerAnglesXYZ() print(Y*180/math.pi) --> 79.999990842554
CFrame.Angles is WEIRD, or toEulerAnglesXYZ() is weird.
|
|
|
| Report Abuse |
|
|
|
| 12 Aug 2012 11:16 AM |
| toEulerAnglesXYZ() only gives rough values - it's by no means ideal and shouldn't be used for such rotations. However it may have changed since I last looked. :/ |
|
|
| Report Abuse |
|
|
rayoma
|
  |
| Joined: 13 Nov 2009 |
| Total Posts: 1911 |
|
|
| 12 Aug 2012 11:33 AM |
| toEulerAngles has never been accurate. If you want to get the actual rotation just do (direction-direction.p) |
|
|
| Report Abuse |
|
|
|
| 12 Aug 2012 09:13 PM |
local Direction = VehicleSeat.CFrame BodyGyro.cframe = Direction * CFrame.Angles(0, VehicleSeat.TurnSpeed, 0)
*facedesk* Forgot to drop the .p when I copied... |
|
|
| Report Abuse |
|
|