Near Sensor: hitObject

hitObject
  • Returns the last game object hit.

Type: 
  • KX_GameObject
     
  • Returns None if no game object was hit
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 last game object hit
 
# 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"]

# last object hit
obj_hit = sen.hitObject