Page 1 of 1

Get node direction as a number

PostPosted: Mon Aug 01, 2016 09:07
by Hasan
Hello, is it possible to get the node direction as a number, example: the node direction at the point (0,0,0) is (-270)

is it possible to get this?

Re: Get node direction as a number

PostPosted: Mon Aug 01, 2016 09:45
by Naj
Sorry but what do you mean by "node direction" ?

Re: Get node direction as a number

PostPosted: Mon Aug 01, 2016 11:17
by rubenwardy
Do you mean angle around the y axis?

Re: Get node direction as a number

PostPosted: Mon Aug 01, 2016 14:55
by ozkur
you mean is it pointing left, right, up, down, forwards, or backwards?

Re: Get node direction as a number

PostPosted: Mon Aug 01, 2016 16:02
by DcNdrew
He asks where does the node is facing. North, south, east, west etc. It must be possible in a way.

Re: Get node direction as a number

PostPosted: Mon Aug 01, 2016 17:10
by ozkur
minetest has to call it every single time it draws, right?

Re: Get node direction as a number

PostPosted: Mon Aug 01, 2016 20:08
by Krock
Hasan wrote:the node direction at the point (0,0,0) is (-270)

I assume you want to get the rotation, then you can use this code:
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
-- Get node data
local node = minetest.get_node(vector.new(0, 0, 0))
-- Get dir as vector (x, y, z), but only read the x and z axis (modulo 4)
local dir = minetest.facedir_to_dir(node.param2 % 4)

-- Calculate dir to angle UNTESTED
local angle = 0
if dir.z == 1 then
   angle = 90
elseif dir.x == -1 then
   angle = 180
elseif dir.z == -1 then
   angle = 270
end

Re: Get node direction as a number

PostPosted: Mon Aug 01, 2016 20:26
by Hasan
@Naj: i mean the node angel which is only 4 directions i think it is 0, 90, 180, 270
@rubenwardy: yeah that what i was mean
@Krock: i will try your code and tell you about the result

And thank you all guys ;)

Re: Get node direction as a number

PostPosted: Mon Aug 01, 2016 20:35
by Hasan
Krock wrote:
Hasan wrote:the node direction at the point (0,0,0) is (-270)

I assume you want to get the rotation, then you can use this code:
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
-- Get node data
local node = minetest.get_node(vector.new(0, 0, 0))
-- Get dir as vector (x, y, z), but only read the x and z axis (modulo 4)
local dir = minetest.facedir_to_dir(node.param2 % 4)

-- Calculate dir to angle UNTESTED
local angle = 0
if dir.z == 1 then
   angle = 90
elseif dir.x == -1 then
   angle = 180
elseif dir.z == -1 then
   angle = 270
end


Thank you very much Krock, that what i needed indeed!
Thank you all guys.