0
$\begingroup$

I want to add a sensor to each of several "players" using the bge + python. Each sensor will need to have its own distance function, because each player has a different range of perception. This is how I add the players to the scene:

for i in range(world_config.initial_population_size):
    pos = Vector((random.uniform(-10,10),
                 random.uniform(-10,10),
                 3))
    p = Player()
    t = own.scene.addObject("Player")        
    t["Player"] = p
    t.worldPosition = pos

Now I would like to do something like.

t.addSensor(Distance=t["Player"].perception())

So that later I can compare which player sees the other in an interaction.

$\endgroup$

1 Answer 1

1
$\begingroup$

There is no function addSensor in the API search_1 API search_2.

So you can't add a sensor through python. The sensor requires to be added in logic editor for a single object, but you can add an object with a sensor and controller to the current scene.

$\endgroup$
2
  • $\begingroup$ Thanks. Do you have advice on how to alter the sensor's "Distance" per object? E.g., so every Player can have their own distance? $\endgroup$ Commented Oct 3, 2017 at 15:42
  • 1
    $\begingroup$ With currentController.sensors['sensor_name'].distance = value, KX_NearSensor KX_RadarSensor $\endgroup$ Commented Oct 3, 2017 at 15:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .