Game Object: rayCastTo

rayCastTo(other, disance, property)
  • Returns the game object that trips rayCastTo.
  • Acts like a laser beam trip wire between one object and an object/position.

Return type:

  • KX_GameObject

other:

  • Type:  KX_GameObject (object center) or  Position  [ x, y, z ]  World coordinates.
distance:
  • Type:  float
  • distance can be negative (look behind the object rayCast is attached to).
  • distance = 0.0  (Ray stretches all the way to the other object center or position.)
property:
  • Property on an object that triggers the ray.
  • property = ""  (All properties trigger ray.)
Note:
  • Returns None if it doesn't find anything.
  • The ray detects ghost objects.
  • The ray ignores objects with Object type: No collision
  • The ray ignores faces that don't have the collision flag enabled.
Sample Code

################### get the Game Object that trips rayCastTo.
  

# import bge
import bge

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

# get object that controller is attached to
obj = cont.owner

# get the current scene
scene = bge.logic.getCurrentScene()

# get a list of the objects in the scene
objList = scene.objects

# get the object named Cube
cube = objList["Cube"]

# raycast to game object named "Cube"
other = cube

# Ray stretches all the way to the other object center
distance = 0.0

# property on an other object that will trip the ray
property = "BlueTeam"

# get GameObject, hit position and angle.
hit = obj.rayCastTo(other, distance, property)