This is confusing.
Am used that rotations are set in 0-360 degree's in properties.
But now i script and use that i get problems.

Because it's not displayed in 0-360 degree. but in some weird - and + numbers.  As far i see i convert it correct to degree.

But if i use the numbers from the properties in my C# program the rotation results are not the same. Still looking into it. But for people it's more readable if it's just in degree. and not like this

0.0 , 0.0, 135.0
0.0 , 0.0, -135.0

Degree is especially important for normal users to make it more readable.

What is the rotation field right now ? Degree, angles or ?

• Galen

This is not a bug. I prefer the -360 to 360 approach. You can also type in the positive value if you prefer.

If you want to know what a negative degree value's positive value is, just add 360 to it. For example, -135 + 360 = 225. Note that -135 has a smaller absolute value than 225, which is why the algorithm favors it.

• Galen

Regarding scripting, they should be consistent in the correct context. If, for example, you use RigidBodyComponent.SetOrientation(Quaternion.FromEulerAngles(X, Y, Z)), and X,Y,Z are the same as in the editor, the orientation should be the same.

Just to be sure we are on the same page, Quaternions do not use degrees for their inputs. And Euler angles do not use degrees, either. If you are using Quaternion.FromEulerAngles() and you have a settings vector representing a rotation, be sure to multiply the X,Y, and Z components by Mathf.RadiansPerDegree to convert it to radians before plugging it into .FromEulerAngles().

• Richardus Raymaker

It still keeps a bit confusing, you can type 225 in that window and then it get converter to a wrong number. For users that can be confusing. And i hate Quaternion my whole virtual life.
Degree is a better easy to understand systemn.

all my life. never did understand it

I used AngleZ = (float)(Math.PI / 180) * rot.Z;
But somewhere the rotation of the same object model is not the same as my waypoint. I just copied the settings from properties rotation.

So far i have not figured out what is going wrong.
Last code i tried.

`AngleX = (float)(Math.PI / 180) * rot.X;AngleY = (float)(Math.PI / 180) * rot.Y;AngleZ = (float)(Math.PI / 180) * rot.Z;Quaternion Rotation = Quaternion.FromEulerAngles(new Vector(AngleX, AngleY, AngleZ,0));Quaternion NewOri = RigidBody.GetOrientation() * Rotation;RigidBody.SetOrientation(QuaternionToVector(NewOri));`

Problem wit this code is that my object is lost, mabye under the floor or so. i now made the desinty lighter. that fixed the problem of missing object. But the rotation is doing still very strange. Just like the numbers i used from properties rotation are not correct.

• Gindipple

your problem isn't about degrees it's about how quanternians work and why they are a good thing.

they solve gimbal lock, which has to do with losing a rotational frame of reference. this is the same thing in SL. if you rotate something it may end up spitting out new numbers for you. you really only need to know that it is a messy 4x4 matrix and tat it works. use the surface of it, don't try to understand them too deeply

and always try/catch your code, rotations can throw errors too

• Richardus Raymaker

Not working on try catch right now. still try to understand everything else. And waiting for a good log reading.

try/catch is easy. I first need a working rotation system.

• Gindipple

By skipping try catch you may have an error and you will never know it.

At the very least implement the UnhandledException handler

• Galen

Also, use Quaternion.Normalize(). I found a piece in my rotation scripts would occasionally throw an exception. Since I added normalization in, I've never seen the exception.

Edited by Galen
• Galen

The Mathf class comes with some useful constants, including:

• .PI
• .PiOverTwo
• .TwoOverPi
• .TwoPi

Here's an example of how you might use this during initialization:

`Rot.W = 0;  // For some reason, a setting has this as 1!Rot *= Mathf.RadiansPerDegree;  // Convert to radiansQuaternion RotQuat = Quaternion.FromEulerAngles(Rot).Normalized();`

Please note that hack to set .W to 0. I have no idea why this isn't zero by default. You can't even see or edit it in the setting editor. But whatever.

Edited by Galen
• Galen

Regarding RigidBody.SetOrientation(), use the one that takes a Quaternion argument. Don't bother with the dubious version that accepts a vector. I.e.:

`Quaternion NewOri = RigidBody.GetOrientation() * Rotation;RigidBody.SetOrientation(NewOri);`

This got hot-fixed over a month ago.

Edited by Galen
• Richardus Raymaker

Big thanks to @galen.

`Rot.W = 0;  // For some reason, a setting has this as 1!Rot *= Mathf.RadiansPerDegree;  // Convert to radiansQuaternion RotQuat = Quaternion.FromEulerAngles(Rot).Normalized();`

That seems todo the trick. Only at 0,0,0 it's doing strange.
I go study that. it helps at least to get forward.

• Galen

The main reason Euler angles vector 0,0,0 does strange things is that there is no clear axis of rotation like there is for every other valid value. It is essentially a "don't rotate at all" value. Be sure you're setting RotationVector.W to 0, though! And calling Quaternion.Normalize(), which should get rid of that error.

• Richardus Raymaker

Moving this from bug to scripting.
The numbers i used from properties are fine.
The only bugs we found are in my code.

Edited by Richardus Raymaker
• Richardus Raymaker

I don't get it. i made the program so it use SetAngularVelocity() that worked perfect in one direction. I did add the otehr direction. and that seems to fail or not work good.

At the end the object keeps rotating and is not stopped anymore. Some parameters i compare looks liked it's swapped. I betetr switch to degree's that's reliable and no negative numbers.

• Galen

Okay, so there are three concepts of rotation already in the script API. One is the raw, fixed orientation. Think of this as being like setting a plate on the table with some fixed rotation. The second is an angular velocity, which you can think of as being like setting a top spinning. The third is an angular impulse which is a little like sticking your foot off the playground merry-go-round and giving a kick to speed it up a little.

If you are wondering, I use RigidBodyComponent.SetOrientation() in my animations. Managing complex velocities, let alone momentum (with impulses), is super complicated and hard to get the precision of movement that I want. The downside is that my objects are effectively instantaneously teleporting from location to location instead of "physically" moving. This screws with the physics engine, making most of my dancing objects impossible to interact with in "natural" ways. But it makes computations much easier.

• Richardus Raymaker

@Galen, I have a waypoint system that moves smooth between the points. turn work, and still work. I think i did have i think smooth turn. But for some reason the smooth turn broke.

And we really need a sit script ! But then you want a smooth turn or i need to change my idea.

I need to stop and look tomorrow at it again. Something is going wrong and it's hard to find because.

• Richardus Raymaker

This need to be fixed, it's complete fault to work in -180 to +180 It gives so much problems with programming and comparing. Also just basic looking at something inside the editor is hard.

It's right now wrong. It need to be converted to 0-359 degree or give a few options so people can choice between radians, fake degree (-/+ 180) or correct degree 0-359

• Galen

This is a matter of opinion. And I disagree with you on this.

• Richardus Raymaker

I see use in both. I see use in - and + 180 to.
But at times i like to see 0-359 degree in properties to.

Best solution would be if the user can choice what to display in properties with a pulldown and preset in settings for default.

• Galen

This seems like a good idea. But I wouldn't put that in the properties window and I don't see LL giving up that real estate to do it. This should probably wait until they implement a true preferences editor.

• Richardus Raymaker

I think it's good to have next to what properties is showing now also radians as output. combined with vector copy. Then you can work with radians and compare the output with properties radians.

• Galen

By the way, almost nobody deals in radians for angles in common thinking and expression. Almost everyone deals in degrees. It is quite a solid standard.

Radians are useful for mathematicians and programmers, but even we usually prefer to talk about degrees.

Edited by Galen
• Richardus Raymaker

I know. but sansar C# not :P
That seems to work with a choas of radians, angles and degree. anbd if you need to use degree from properties as start and you cannot compare it with. You get in the position i am.

• Gindipple

Chaos?

Let's say you're a carpenter and you have a board cutting saw that cuts boards in lengths of inches.

Now I come to you and say hey can you cut me 100 boards of size 1.3 meters for \$1000?

You going to close up shop?

Let's also say that you only know that there's 2.54 cm in an inch.

Luckilly we have invented math.

(2.54 cm / 1 inch) that is a unit factor it is like saying 5 / 5

Both of them equal 1.

with that in mind we can multiply it by anything and not alter it. And we can even multiply the recipricol of it and get the same result.

so we have 1.3 meters and we need inches.

1.3 meter * (1 inch / 2.54 cm)  * (100 cm / 1 meter) after we cancel the units we are left with 1.3 * 100 / 2.54 inches. rounding off we get about 51 1/4 inches.

Now you need to tell the customer what you can do for him, more conversions.

51.25 inch * (2.54 cm / 1 inch) * (1 meter / 100 cm) = 1.301 meter

Customer is like ok that's acceptable!

Profit.