Class KX_GameObject -- Blender Game Engine 2.49b



 
  



rayCast

 
rayCast(to, from, distance, property, face, xray, poly)


Casts a ray from one object/point to another object/point.  Returns the first object hit that has the correct property.  

Returns the game object, the hit point and hit normal (poly = 0)
or
Returns the game object, the hit point, hit normal and polygon (poly = 1)

Method Parameters
to:
Type:  KX_GameObject
   or
   Position  [ x, y, z ]  World coordinates.
from:
Type:  KX_GameObject
   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
face:
Type:  int
   1 = return face normal
   0 = normal is oriented towards origin
x-ray:
Type:  int
   1 = x-ray on.  Check behind objects that don't have property
   0 = x-ray off.  Only check first object hit.
poly:
Type:  int
    1 = return polygon (KX_PolyProxy)
    0 = don't return polygon (KX_PolyProxy)

Return type:
poly = 0
list [ GameObject, hit, normal]
    Returns [ None, None, None] if nothing was hit.
poly = 1
list [ GameObject, hit, normal, polygon]
    Returns [ None, None, None, None] if nothing was hit.

Return Parameters
GameObject:  The game object that triggered the ray.
Type:  a KX_GameObject
hit:   The position of the hit.  (The distance from the starting position of the ray.)
Type:  List [ x, y, z]
normal:  The normal of the surface that the ray hit.  (The angle of the hit.)
Type: list [ x vector, y vector, z vector]
polygon:
Type:  KX_PolyProxy

Note:
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 controller rayCast is attached to
controller = GameLogic.getCurrentController()

# get game object rayCast is attached
obj = controller.owner

# get the current scene 
scene = GameLogic.getCurrentScene()

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

# get the object named Cube that rayCast is pointing at
cube = objList["OBCube"]

# get GameObject, hit position and angle. 
hit = obj.rayCast( cube, obj, 0.0, "blueTeam", 1, 1, 0)

 
Game developers can use the game engine to create casual video games, first and third person shooters, role playing games, racing simulations and more. The game engine can be used to make both 2D games and 3D games.  Beginning game developers will only need basic knowledge of game design and programming to create rich and complex game models with photo realistic textures to add detail to the graphics of the video game.  Today's games need more than good looking low polygon game models.  Use normal maps and photo realistic textures to create high quality game models.