Ray sensor

The Ray sensor, like the Collision , Near and Radar sensors is designed to detect objects around. Detects a game object with the selected Material/Property when under the Ray and sends a positive pulse. Any more objects detected in the same time will not send extra pulses. When no more objects are detected by the ray sensor, a negative pulse is sent to the controller.

Option(s) of the Ray sensor :

  • X-Ray Mode ( Enabled ) : Allows the Ray to see through game objects that don't have the selected Material
  • Range : Distance from the game object center that will trigger / deactivated Ray sensor
  • Axis : Direction the ray points
  • M/P : Toggle between using a Material or a Property for collision detection. (For material mode, leave blank to react to all materials)
  • Material Name : Only objects with the selected Material will trigger/reset the sensor. Leave blank to react to all game objects
  • Common options of all Sensors

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.hitObject : Returns the last object hit in this frame
  • sen.hitPosition : Returns the position where the object was hit by the ray ( float List / [ x, y, z] )
  • sen.hitNormal : Returns the normal as a 3D vector (float list / [ nx, ny, nz] with distance normalized to 1 )
  • sen.axis : Get/set the game object Axis that the ray uses ( integer / +X,+Y,+Z,-X,-Y,-Z = 0,1,2,3,4,5 )
  • sen.range : Get/set the Range of the ray (float / 0.01 - 10,000.00 )
  • sen.rayDirection : Returns the direction (in World Coordinates) that the ray is pointing ( float List / [ dx, dy, dz ] )
  • sen.propName : Get/set the name of the property/material
  • sen.useMaterial : Get/set if sensor is looking for a Material or a Property
  • sen.xRay : Get/set if sensor is using X-Ray Mode

Note:

Ray Sensor can be blocked (doesn't see through walls etc.)

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License