Page 1 of 1

[SOLVED] LuaEntitySAO, getyaw and degrees

PostPosted: Wed Aug 28, 2013 19:04
by JKMurray
Hey,

I'm working on a mod which adds some animals to the game. As a base I downloaded the Mobs for Minetest by PilzAdam. I want to extend it with some more functionality, like stop animals from walking and jumping over fences.

To do this I need to know where the Entity is heading. For that I use the getyaw, which tells me everything I need to know in radians. It should be possible to calculate the degrees by using this formula:

Radians / pi * 180

In code that should be as simple as this:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local yaw = self.object:getyaw()
local degr = yaw / math.pi * 180


The problem however is that I get values over 360 degrees. 460, 520 etc. are not uncommon. Also, there are negative values returned, which also calculate to a negative degree.

So my question is: what is the correct way to calculate the angle in degrees the Entity is heading? Or even easier: what's his direction in degrees? I searched the forums, the api and Googled my may around the internet, but I can't find something that gives me the answer.

Thanks in advance!

PostPosted: Wed Aug 28, 2013 19:42
by PilzAdam
Just do something like:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
degr = degr % 360

PostPosted: Wed Aug 28, 2013 20:00
by JKMurray
PilzAdam wrote:Just do something like:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
degr = degr % 360


Wow, is it actually that easy? Well, it is, because it works like a charm. Thank you!!