Get face orientation

How to get orientation (rotation in global space) of particular face posibly with rayCast(). I know there’s the normal parameter, but I’m getting just 1 or 0 based of the normal orientation.

Hope you understand this.

A normal is a vector

ok, so i have this script…


import bge


scene = bge.logic.getCurrentScene()
cont = bge.logic.getCurrentController()
own = cont.owner


Hit = scene.objects["Hit"]
print(own.rayCast(own, Hit, 0.0, "Ground", 1, 1, 0)[1])


own.worldOrientation(own.rayCast(own, Hit, 0.0, "Ground", 1, 1, 0)[1])

and i get his error:


<Vector (3.2972, 0.9015, -0.3866)>
Python script error - object 'BasicSledge', controller 'Python':
Traceback (most recent call last):
  File "sliding.py", line 10, in <module>
TypeError: 'Matrix' object is not callable

i just want the object to rotate according to the normal of the object below it.

You need to ensure the ray cast returns an actual value other than a list of 'None’s, and worldOrientation is a Matrix, so you shouldn’t directly assign the result of the ray cast to it. You could use alignAxisToVect() instead.


import bge


scene = bge.logic.getCurrentScene()
cont = bge.logic.getCurrentController()
own = cont.owner


Hit = scene.objects["Hit"]

ray = own.rayCast(own, Hit, 0.0, "Ground", 1, 1, 0)[1]

if ray != None:
     own.alignAxisToVect(ray, 2)

Just for information:


own.worldOrientation

returns a Matrix. ( ) on a Matrix leads to the above TypeError.

I think you simply mixed that up with setWorldOrientation( Matrix ).

Beside that: Solarlune is right, better align along the vector.

[1] return the position not the normal


Hit = scene.objects["Hit"]


ray = own.rayCast(own, Hit, 0.0, "Ground", 1, 1, 0)


if ray[0] : #if is valid the first is valid also the others
    own.worldPosition = ray[1]
    own.alignAxisToVect(ray[2], 2)

and yes , better using alignAxisToVect , this change directly worldOrientation (in easy way)

the matrix of the face I not think is useful

PS: I not sure if work as excpected , you have to make the ray from another obj i think, not from own