Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Tort |
Hey. I use GridMap. I tried get_cell_item_orientation
Why does it return an integer?
Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Tort |
Hey. I use GridMap. I tried get_cell_item_orientation
Why does it return an integer?
Reply From: | Zylann |
I believe this is an index to a lookup table containing all possible combinations of rotations for a 3D cell that can rotate by steps of 90 degrees. Think of it as the combination of an axis and a rotation around that axis. There are 6 axes (X, Y, Z, -X, -Y, -Z) and 4 rotations (0, 90, 180 and 270 degrees), so that gives 24 possible rotations.
This index can be converted into a Basis
(which itself can also be converted to a Quat
) using the Basis.set_orthogonal_index
function, but this C++ function is not exposed to GDScript
Exactly
I tortured the keyboard a little
func orthogonal_hren(value):
if value == 0:
return(Vector3(0, 0, 0))
elif value == 1:
return(Vector3(0, 0, PI/2))
elif value == 2:
return(Vector3(0, 0, PI))
elif value == 3:
return(Vector3(0, 0, -PI/2))
elif value == 4:
return(Vector3(PI/2, 0, 0))
elif value == 5:
return(Vector3(PI, -PI/2, -PI/2))
elif value == 6:
return(Vector3(-PI/2, PI, 0))
elif value == 7:
return(Vector3(0, -PI/2, -PI/2))
elif value == 8:
return(Vector3(-PI, 0, 0))
elif value == 9:
return(Vector3(PI, 0, -PI/2))
elif value == 10:
return(Vector3(0, PI, 0))
elif value == 11:
return(Vector3(0, PI, -PI/2))
elif value == 12:
return(Vector3(-PI/2, 0, 0))
elif value == 13:
return(Vector3(0, -PI/2, PI/2))
elif value == 14:
return(Vector3(PI/2, 0, PI))
elif value == 15:
return(Vector3(0, PI/2, -PI/2))
elif value == 16:
return(Vector3(0, PI/2, 0))
elif value == 17:
return(Vector3(-PI/2, PI/2, 0))
elif value == 18:
return(Vector3(PI, PI/2, 0))
elif value == 19:
return(Vector3(PI/2, PI/2, 0))
elif value == 20:
return(Vector3(PI, -PI/2, 0))
elif value == 21:
return(Vector3(-PI/2, -PI/2, 0))
elif value == 22:
return(Vector3(0, -PI/2, 0))
elif value == 23:
return(Vector3(PI/2, -PI/2, 0))
Tort | 2019-03-22 20:17
But I just copy pasted that, XD, and also I recommend using a match statement instead.
sairam123 | 2020-10-21 20:39
I recommend an array
const orthogonal_angles = [
Vector3(0, 0, 0),
Vector3(0, 0, PI/2),
Vector3(0, 0, PI),
Vector3(0, 0, -PI/2),
Vector3(PI/2, 0, 0),
Vector3(PI, -PI/2, -PI/2),
Vector3(-PI/2, PI, 0),
Vector3(0, -PI/2, -PI/2),
Vector3(-PI, 0, 0),
Vector3(PI, 0, -PI/2),
Vector3(0, PI, 0),
Vector3(0, PI, -PI/2),
Vector3(-PI/2, 0, 0),
Vector3(0, -PI/2, PI/2),
Vector3(PI/2, 0, PI),
Vector3(0, PI/2, -PI/2),
Vector3(0, PI/2, 0),
Vector3(-PI/2, PI/2, 0),
Vector3(PI, PI/2, 0),
Vector3(PI/2, PI/2, 0),
Vector3(PI, -PI/2, 0),
Vector3(-PI/2, -PI/2, 0),
Vector3(0, -PI/2, 0),
Vector3(PI/2, -PI/2, 0)
]
# Use:
var angles = orthogonal_angles[index]
Zylann | 2020-10-21 22:32
Is radians or degrees?
I mean I use only use y axis.
I’ll edit this comment with my function, when I get to my PC.
sairam123 | 2020-10-22 19:33
Well, do you know how to expose that?, I’m trying to expose it, but I don’t know how.
sairam123 | 2020-11-19 01:42