Skip to content


core: Add dir_to_yaw and yaw_to_dir helpers
Browse files Browse the repository at this point in the history
These are needed to go from things like entity yaw to a vector
and vice versa.
  • Loading branch information
sofar authored and paramat committed Jan 23, 2017
1 parent 2d7a6f2 commit 7fc6719
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions builtin/game/item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ function core.wallmounted_to_dir(wallmounted)
return wallmounted_to_dir[wallmounted]

function core.dir_to_yaw(dir)
return -math.atan2(dir.x, dir.z)

function core.yaw_to_dir(yaw)
return {x = -math.sin(yaw), y = 0, z = math.cos(yaw)}

function core.get_node_drops(nodename, toolname)
local drop = ItemStack({name=nodename}):get_definition().drop
if drop == nil then
Expand Down
4 changes: 4 additions & 0 deletions doc/lua_api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2403,6 +2403,10 @@ and `minetest.auth_reload` call the authetification handler.
* Convert a vector to a wallmounted value, used for `paramtype2="wallmounted"`
* `minetest.wallmounted_to_dir(wallmounted)`
* Convert a wallmounted value back into a vector aimed directly out the "back" of a node
* `minetest.dir_to_yaw(dir)`
* Convert a vector into a yaw (angle)
* `minetest.yaw_to_dir(yaw)`
* Convert yaw (angle) to a vector
* `minetest.get_node_drops(nodename, toolname)`
* Returns list of item names.
* **Note**: This will be removed or modified in a future version.
Expand Down

0 comments on commit 7fc6719

Please sign in to comment.