Near sensor

The near sensor works a bit like the collision sensor. It sends a positive pulse when an object (with the option "actor" enabled 1) is closer than a given distance but another object getting close won't trigger another pulse.
The sensor will be reset when all objects are no longer detected (are beyond a given distance)

Option(s) of the Near sensor :

  • Property :
    • Only objects with Actor enabled with this Property will trigger/reset the Near sensor
    • Leave blank to react to all objects with Actor enabled
  • Distance : Distance from the object center that will trigger the Near sensor 2
  • Reset Distance : Distance from the object center that will reset a Near sensor (a negative pulse is sent to the connected controller(s))
  • Common options of all Sensors

Python :

# import bge module
import bge
 
# get the controller
cont = bge.logic.getCurrentController()
 
# get the sensor attached to the controller
# my sensor is named Trigger
sen = cont.sensors["Trigger"]
  • sen.distance : gets/sets the distance (from the object center) that triggers the Near Sensor when an object approaches. (range : 0 to 10,000.00 )
  • sen.hitObject : Returns the last game object hit . Returns "None" if no objects are detected
  • sen.hitObjectList : Returns a list of the objects hit in the last frame
  • sen.propName : gets/sets the name of the property that the near sensor looks for
  • sen.resetDistance : gets/sets the distance (from the object center) that resets the Near Sensor when an object leaves. (range : 0 to 10,000.00 )

Note:

  1. Only detects game objects that have Actor enabled. ( Properties menu » Physics button » Physics tab » Actor)
  2. Near Sensor can't be blocked. Sees through walls etc.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License