Collision Sensor: hitObjectList

hitObjectList
  • Pulse Enabled:  Returns a list of all objects with the selected material/property colliding with the game object.
  • Pulse Disabled:  Returns only the first object with the selected material/property colliding with the game object.

Type: 
  • List [ KX_GameObject ]
  • Returns [] (empty brackets) if there isn't an object with the selected Material/Property touching it.
Collision Sensor:
  • Leaving the Material/Property blank will cause the Collision Sensor to react to collisions with any game objects no matter what Material/Property they may have (this includes objects that don't have any Materials and/or Properties).
     
  • A collision with an object having the material/property sends a positive pulse to the connected controller(s) only if the game object isn't already touching an object with the material/property.
  • Continuously touching any game object with the material/property:  No pulses are sent to the connected controller(s).
  • Removing (no longer touching) all game objects with the material/property:  One negative pulse is sent to the connected controller(s).
Sample Code


################  Get a list of the objects hit in the last frame

# import bge module
import bge

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

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

sen = cont.sensors["Explode"]

# get a list of the objects hit in the last frame
objList = sen.hitObjectList