local ray angle direction

does any1 know if it’s possible to get something like rayDirection, but in the Local axis
I would like to check if my object is aligned to the ground (with the local -z axis)
and if it’s possible to know also the angle between them.

I tried also with hitNormal but I’m not sure if it’s not functioning or i just didn’t write it correctly

You can convert a vector in world space to an object’s space by multiplying the vector by the object’s orientation matrix and you can return back to world space multipling to local vector by the inverse of the object’s orientation matrix, the use of the mathutils Vector and Matrix classes help here, if you are on 2.5 you don’t need to worry about that though.

world_vector = local_vector * obj.worldOrientation
local_vector_again = world_vector * obj.worldOrietnation.copy().invert()

Angles between vectors can be found using the .angle() method of a Vector:

import math

angle = math.degrees(vector1.angle(vector2)) # the return type is in radians.

As for seeing if your object is aligned to the ground, something like this should be helpful:

import math

obj = ...
hit_normal = ... # in world space

angle = math.degrees(obj.worldOrietnation[2].angle(hit_normal))
if angle < acceptable_alignment_threshold: # such as 10, depends on how rough your ground is
    print("object is aligned to ground")