minetest.facedir_to_dir

From Minetest Developer Wiki
Jump to: navigation, search

Syntax

minetest.facedir_to_dir(facedir)

Description

Convert a facedir value to a vector, which points out of the back of a node.

6d facedir is actually defined according to the "top" vector; that can be obtained like this:

local topdir = ({[0]={x=0, y=1, z=0},
		{x=0, y=0, z=1},
		{x=0, y=0, z=-1},
		{x=1, y=0, z=0},
		{x=-1, y=0, z=0},
		{x=0, y=-1, z=0}})[math.floor(facedir/4)]

The "right" vector can then be obtained via the cross product:

local rightdir = {x=topdir.y*backdir.z - backdir.y*topdir.z,
		y=topdir.z*backdir.x - backdir.z*topdir.x,
		z=topdir.x*backdir.y - backdir.x*topdir.y}

See also: minetest.dir_to_facedir()

Example

dir = minetest.facedir_to_dir(0)
-- dir == {0, 0, 1}
Personal tools
Namespaces

Variants
Actions
Navigation
API
Toolbox