[SOLVED] Convert radians to degree

Hello, i have tried different things to convert radians to degree and maybe it works, but how can i get a value from an entity rotation that is convertible to radians to rotate an image? getEulerAngles don’t seems to be the case and i’m a bit loss.

1 Like

Well, to convert degrees to radians, you do:

var radians = degrees * Math.PI / 180;

The three angles returned by getEulerAngles must be considered together. You cannot just consider the y rotation, say.

Often, I do something like this. If an entity is sitting on the XZ plane and I want it’s Y rotation (knowing that it only has a Y rotation), I just use Math.atan2 using the entity’s world-space X axis.

// Get y-rotation in radians
var yrot = Math.atan2(this.entity.right.x, this.entity.right.z);

Hello @will your solution almost works i have this

            this.needlePaper = Raphael(10,this.screenHeight-90,80,this.screenHeight-10);           
            var yaw = Math.atan2(app.root.findByName('Player').right.x, app.root.findByName('Player').right.z);
            var yaw_degrees = yaw * (180/Math.PI); // conversion to degrees
            if( yaw_degrees < 0 ) yaw_degrees += 360.0; // convert negative to positive angles
            this.write(yaw_degrees); // this just show the degrees in a box
            var needle= this.needlePaper.image(this.needle,0,0,80,80).attr({

and it works…just the needle rotate in the oppsite direction coz the degrees are reversed :slight_smile: as i rotate to right with player the degrees decrease instead increase

So are you OK now? You know what to negate?

nope :smile: i can’t figure out :stuck_out_tongue:

Well, I can’t figure it out in my head, but I would probably try negating yaw_degrees or either of the two parameters passed to atan2. Does one of those work?

1 Like

Yes just inverting the params in atan2 like this var yaw = Math.atan2(app.root.findByName(‘Player’).right.z, app.root.findByName(‘Player’).right.x);
now works perfectly thanks @will

1 Like