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!