|
rayCastrayCast(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 tocontroller = GameLogic.getCurrentController()# get game object rayCast is attachedobj = controller.owner# get the current scenescene = GameLogic.getCurrentScene()# get a list of the objects in the sceneobjList = scene.objects# get the object named Cube that rayCast is pointing atcube = objList["OBCube"]# get GameObject, hit position and angle.hit = obj.rayCast( cube, obj, 0.0, "blueTeam", 1, 1, 0) |