Collision Sensor: hitObject

hitObject
  • Pulse Disabled: Returns the only the first object colliding with it that has the selected Material/Property.
  • Pulse Enabled: Returns the all objects colliding with it that has the selected Material/Property.

Type: 
  • KX_GameObject
     
  • Returns None if there isn't any objects 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 the first object touching

# 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 first object touching
obj = sen.hitObject