How do I determine if there is an object (e.g. wall) between two objects?

Hello, I am using the game engine to transmit an infection between two objects if they are near each other. If there is a wall or other object separating them, I don’t want to transmit the infection. How can I determine if there is such an intermediate object? My initial thought was to use the KX_RaySensor, but I can’t determine how to set the ray direction to that of the nearby object. Searching hasn’t surfaced anything helpful yet. Any suggestions are much appreciated!

you will have to use python to cast a ray between the objects.

object.rayCastTo(otherObject, maxDistance, “property”)

“property” should contain the name of a property that the wall contains. When the it casts a ray between the objects, and it sees that property, it will return the object that it hits. If it hits nothing, it will return None.

Another solution would be (if you have only two objects that you want to compare between) to have an empty with a track to actuator pointing to the other object. Then you can put a ray sensor on the empty.

Thanks so much! That sounds like exactly the method I need!

another simple way is spawn some “obj infected” (we say with a little life time),
this obj can be one obj dynamic that simply bounce on the wall so cannot infect
the object after the wall.