Raycast not working: code included

own = parent object which is a plane (ground)

empties are the children, they are parented and have a higher z axis than the plane

ground property IS on the parent, this hasn’t been forgotten

YET, the raycast is not returning ground_ray[0]

collision is triangle mesh on the plane but i dont think that matters.
there Is a material with physics enabled on the plane but i dont think that should matter either

for object in own.children:
    start = object.worldPosition
    end = object.worldPosition + Vector([0,0,-400])
    ground_ray = object.rayCast(end,start,0,'ground',0,1,0)   
    if ground_ray[0]:
        print('ground ray positive')
        object.worldPosition = ground_ray[1] + Vector([0,0,1])

I was aware that calling obj.rayCast will exclude obj from collisions checks. Apparently obj’s parent is also excluded. You can get around this by calling obj.removeParent before casting the ray (you can re-parent it after if you want), or by just using a proxy object for the ray cast instead of the child object.


logic.getSceneList()[0] is dangerous as you can’t guaranty the first scene is the current scene.

Better use object.scene, owner.scene or bge.logic.getCurrentScene().