How would it be possible to parent a object to a object with a particular property and only the one that is near the object?
Well, you would have to cycle through all the objects in your scene. While your doing that check the object for the property, and if it has the property get the distance to it.
something like this would probably work:
from bge import logic
scene = logic.getCurrentScene()
own = logic.getCurrentController.owner()
prop = "property"
distance = 10000
closestObject = None
for object in scene.objects:
if prop in object:
dist = own.getDistanceTo(object)
if dist < distance:
distance = dist
closestObject = object
own.setParent(closestObject)
Something like that should work, but I didn’t test it.
Sounds like a task for the near sensor.
KX_GameObject.setParent( newParent ) will do the trick.
Edit:
the S2A can do this already. Look for closestHitObjectToObject
Near Sensor -> Python Controller -> Parent Actuator
This is what i am trying to do.Make a marching cubes similar to planet explorer.I will add static pieces of ground to the game and then parent a added object that is added with the add object actuator to the ground pieces i want to get rid of.By using the end object actuator.It will only end the pieces of ground with the nearest property.The ground pieces are static objects.