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
$\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.

| improve this answer | |
$\endgroup$
  • $\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$ – Brian Dolan Oct 3 '17 at 15:42
  • 1
    $\begingroup$ With currentController.sensors['sensor_name'].distance = value, KX_NearSensor KX_RadarSensor $\endgroup$ – Strapicarus Oct 3 '17 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.