[SOLVED] LuaEntitySAO, getyaw and degrees

User avatar
JKMurray
Member
 
Posts: 31
Joined: Sat Aug 24, 2013 21:20

[SOLVED] LuaEntitySAO, getyaw and degrees

by JKMurray » Wed Aug 28, 2013 19:04

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!
Last edited by JKMurray on Wed Aug 28, 2013 20:00, edited 1 time in total.
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Wed Aug 28, 2013 19:42

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
 

User avatar
JKMurray
Member
 
Posts: 31
Joined: Sat Aug 24, 2013 21:20

by JKMurray » Wed Aug 28, 2013 20:00

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!!
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 7 guests

cron