Ray Sensor: hitObject

hitObject
  • Returns the last object hit in this frame

Type: 
  • KX_GameObject
     
  • Returns None if no game object was hit
Ray Sensor:
  • Ray Sensor is triggered when the first game object is detected.
  • Ray 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 object hit in this frame.

# import bge module
import bge

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

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

sen = cont.sensors["Tripwire"]

# get the last object hit
obj = sen.hitObject