Godot: set_rot() is in degree in editor but in radian in script

Created on 1 May 2016  Â·  9Comments  Â·  Source: godotengine/godot

Operating system or device:
Windows 10 Pro

Issue description (what happened, and what was expected):
When setting rot from script you must use deg2rad, but in editor it's in degree. It was supposed to be either everything in radians or in degrees. At the very least something in the docs saying that it was in radian.

Steps to reproduce:
Attach a new script to a sprite and write set_rot(80). It's going to be completely erroneous. Now put set_rot(deg2rad(80)). It works just fine.

enhancement editor usability

Most helpful comment

This behavior is intended, Godot works with radians internally, but will
show degrees when presented to the user via the UI.

On Wed, May 4, 2016 at 9:41 AM, Mattias Cibien [email protected]
wrote:

I guess I read the issue all wrong. Sorry.

Not sure how to fix that without breaking all existing Godot games

exactly what I was thinking.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
https://github.com/godotengine/godot/issues/4511#issuecomment-216850779

All 9 comments

+1. This inconsistency has annoyed me quite a bit. Everything should be the same, presumably in degrees.

I guess this is the offending piece of code:

void Node2D::set_rot(float p_angle) {
    if (_xform_dirty)
        ((Node2D*)this)->_update_xform_values();
    angle=p_angle; //this line
    _update_transform();
    _change_notify("transform/rot");
}

Found here

If needed I can fix it pretty easily i think but I want to ask the devs first to ensure that I am in the right place.

EDIT: i gess that this should also be updated:

float Node2D::get_rot() const {
    if (_xform_dirty)
        ((Node2D*)this)->_update_xform_values();

    return angle;
}

I guess this is the offending piece of code:

The issue is not here, set_rot is defined to use radians in the whole code base, which is pretty normal when doing mathematic operations. In Node2D, you have _set_rotd for degrees.

The problem is here: https://github.com/godotengine/godot/blob/a895e2e372c9df2a9972f38134ae0ea9c8bf45a8/scene/2d/node_2d.cpp#L403
The transform/rot parameter uses the _set_rotd method, so expects degrees. But when switching to GDScript, people use set_rot which expects radians.

Not sure how to fix that without breaking all existing Godot games :)

I guess I read the issue all wrong. Sorry.

Not sure how to fix that without breaking all existing Godot games

exactly what I was thinking.

This behavior is intended, Godot works with radians internally, but will
show degrees when presented to the user via the UI.

On Wed, May 4, 2016 at 9:41 AM, Mattias Cibien [email protected]
wrote:

I guess I read the issue all wrong. Sorry.

Not sure how to fix that without breaking all existing Godot games

exactly what I was thinking.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
https://github.com/godotengine/godot/issues/4511#issuecomment-216850779

As I mentioned on Facebook:

We could maybe expose set_rotd to GDScript, and rename the arguments to "radians" and "degrees" respectively so that the autocompletion makes it obvious.

Will implement that.

@akien-mga thank you. Sorry for the inconvenience.

No problem, I do agree that this apparent inconsistency is confusing, even if it has a good justification as @reduz mentioned.

Thank you !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

karroffel picture karroffel  Â·  144Comments

alelepd picture alelepd  Â·  187Comments

nunodonato picture nunodonato  Â·  143Comments

adolson picture adolson  Â·  87Comments

ghost picture ghost  Â·  161Comments