Near Sensor: distance

distance
  • gets/sets the distance (from the object center) that triggers the Near Sensor when an object approaches.

Type: 
  • float number

Range:

  • 0.00 to 10,000.00
Near Sensor:
  • Game object being detected must have Actor enabled.
Properties menu >> Physics button >> Physics Type >> Actor checkbox
  • Near Sensor is triggered when the first (and only the first) game object is detected.
  • Near Sensor is reset when all game objects are no longer detected.
  • Triggered:  One positive pulse is sent to the connected controller(s).
  • Reset:  One negative pulse is sent to the connected controller(s).
Sample Code


################  Get the distance that triggers the Near Sensor
 
# import bge module

import bge

# get the controller
cont = bge.logic.getCurrentController()

# get the sensor attached to the controller
# my sensor is named Alert

sen = cont.sensors["Alert"]

# distance the triggers near sensor
dist = sen.distance
 
Sample Code


################  Set the distance that triggers the Near Sensor
 
# import bge module

import bge

# get the controller
cont = bge.logic.getCurrentController()

# get the sensor attached to the controller
# my sensor is named Alert

sen = cont.sensors["Alert"]

# set the distance the triggers near sensor
sen.distance = 9.25