The sensors

Generality : The sensors used in the logic bricks system of the BGE are meant to capture all the information that could change the state of the running game.
For exemple, pushing a button on the keyboard, moving the mouse .. but also, events happening on the screen like an object getting close to another one, an animation coming to an end.

You do trigger an event with the sensor ; a positive pulse is sent to the controller(s) connected to it . In most common cases, once the event is over (left button released for example), a negative pulse is sent.

sensors_options.png
The sensor "Always" as an exemple (here doing absolutely nothing as it's unconnected to any existing controllers)

Those options are common to all sensors

  • Type : Always
  • Name : "Always"
  • Pin :
    Enabled: Always display the Sensor
    Disabled: Only display when the State Mask group the Sensor is linked to is being displayed
  • Checkbox :
    Enabled : Sensor is turned on.
    Disabled : Sensor is turned off
  • True Level Trigger :
    Enabled : Sends a positive pulse to the connected controller(s) with each logic tic (The default logic tic rate is 60 per second)
    Disabled : Sends one positive pulse to the connected controller(s)
  • False Level Trigger :
    Enabled : Sends a positive pulse to the connected controller(s) ( The default logic tic rate is 60 per second)
    Disabled : Always sensor activated: Sends a positive pulse to the connected controller(s)
  • Skip : Skips the number of logic tics entered before sending the next pulse (Used with True Level Trigger and False Level Trigger)
  • Level :

Enabled :

  • Switching from a State Mask group the sensor belongs to to a State Mask group it doesn't belong to : Sensor is deactivated
  • Switching from a State Mask group the sensor doesn't belong to to a State Mask group it belongs to : Sends one positive pulse to the connected controller(s)

Disabled :

  • Switching from a State Mask group the sensor belongs to to a State Mask group it doesn't belong to : Sensor is deactivated
  • Switching from a State Mask group the sensor doesn't belong to to a State Mask group it belongs to : Sends one positive pulse to the connected controller(s)
  • Tap :
    Enabled : A positive pulse is immediately followed by a negative pulse (next frame) Even if the condition remains true ! (for example, used with a motion actuator, the object will just move the time of a tick)
    Disabled : A positive pulse is sent to the connected controller(s) True Level Trigger enabled and Skip = 0: Never has a chance to send a negative pulse
  • Invert : Inverts the output of the triggers : A positive trigger event sends a negative pulse ; A negative trigger event sends a positive pulse

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.executePriority : Logic bricks with the highest priority will be executed before logic bricks with lower priority. ( 0 (highest) to 100 (lowest) )
  • sen.frequency : gets/sets the delay between repeated pulses ( 0 to 10,000 )
  • sen.invalid : Returns whether or not a reference to an object (KX_GameObject, SCA_ILogicBrick, KX_Scene, etc.) is invalid or not. (1 = True = object isn't valid ) Note1
  • sen.invert : gets/sets if the output of the sensor is inverted
  • sen.level : gets/sets whether or not the Level button is active. (1 = True = level button active) Note2
  • sen.name : returns the name of the logic brick sensor (type : string)
  • sen.neg_ticks : returns the number of ticks since the last negative pulse.
  • sen.owner : Returns the game object that owns the logic brick. (basically, from which object the logic brick was created)
  • sen.pos_ticks : returns the number of ticks since the last positive pulse.
  • sen.positive : Returns whether or not a sensor is activated ( 1 = True = sensor activated)
  • sen.reset : Resets the sensor to it's initial state.
  • sen.skippedTicks : Get/set the number of logic ticks skipped (0 to 10,000 ) ( Note : Used with True Level Trigger and False Level Trigger)
  • sen.status : Returns the status of the sensor. ( 0 = KX_SENSOR_INACTIVE , 1 = KX_SENSOR_JUST_ACTIVATED , 2 = KX_SENSOR_ACTIVE , 3 = KX_SENSOR_JUST_DEACTIVATED)
  • sen.tap : Get/set the status of the Tap button.
  • sen.triggered : Returns if the sensor has triggered the controller.
  • sen.useNegPulseMode : gets/sets if sensor is set to use negative pulse mode. (1 = True = use negative pulse mode )
  • sen.usePosPulseMode : gets/sets if sensor is set to use positive pulse mode. (1 = True = use positive pulse mode)

Note:

  • Sensors can be connected to more than one controller
  • Sensors connected to a controller(s) belong to the same State Mask group(s) as the controller(s)
  • (1) :
    • Pointers to game data can be stored as a global variable.
    • If the game object is freed/deleted/destroyed, the global variable holds a pointer to game data that no longer exists.
    • Trying to access this data will raise a system error.
    • invalid allows you to test for this case without raising the system error.
  • (2) :
    • The Level button is part of the State Mask Group System.
    • Sensors belong to a State Mask group(s).
    • State Mask groups (and the sensors belonging to them) can be deactivated and reactivated.
    • Level button enabled. Deactivated sensor being reactivated: Checks to see if a mouse button/keyboard/etc is being pressed. If it is, it sends a pulse to the controller.
    • Level button not enabled. Deactivated sensor being reactivated: Doesn't check to see if a mouse button/keyboard/etc is being pressed. Doesn't send a pulse to the controller.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License