probing using raycast

my question is can you use rayCast to receive information from the thing you are casting to? like the objects name and other properties from it?

I’m using ray casting to test if there is a Human in front of the zombie and if so to track to the human. This should be simple enough but what if i have more then one human instance and i want the zombie to track to the specific human (object) it sees which is why i would like to know if you can use rayCast to get the objects name and proprieties from it using ray cast.

Would you have any suggestions as to how I can get this effect?

I just asked the same question lol. Ill let you know if I figure it out. What I am currently working on is establishing which item you are looking at. So when you have say, three guns close together you can use the returned object name from the ray to determine which one it will select/buy. This will work the same with any interactive item.

Here you go! Works like a charm!

def main():
cont = bge.logic.getCurrentController()
own = cont.owner

ray = cont.sensors["ray"]

if ray.positive:   
    hit_object = ray.hitObject
    
    props = hit_object.getPropertyNames()
    
    print(hit_object)
    print(props)
    
    render.drawLine(own.worldPosition, ray.hitPosition, [255, 0, 0])    

main()