| Methods: |
| boxInsideFrusturm |
pointInsideFrustum |
| enableViewport |
setOnTop |
| getCameraToWorld |
setProjectionMatrix |
| getProjectionMatrix |
setViewport |
| getWorldToCamera |
sphereInsideFrustum |
|
| Variables: |
| camera_to_world |
near |
| far |
perspective |
| frustum_culling |
projection_matrix |
| lens |
world_to_camera |
| modelview_matrix |
----------
|
|
| Constants: |
| INSIDE |
OUTSIDE |
| INTERSECT |
----------
|
|
Inherited
Methods: |
| alignAxisToVect |
getState |
| applyImpulse |
getVectTo |
| disableRigidBody |
getVelocity |
| enableRigidBody |
getVisible |
| endObject |
rayCast |
| getAngularVelocity |
rayCastTo |
| getAxisVect |
removeParent |
| getChildren |
restoreDynamics |
| getChildrenRecursive |
setAngularVelocity |
| getDistanceTo |
setCollisionMargin |
| getLinearVelocity |
setLinearVelocity |
| getMass |
setOrientation |
| getMesh |
setParent |
| getOrientation |
setPosition |
| getParent |
setState |
| getPhysicsId |
setVisible |
| getPosition |
setWorldPosition |
| getPropertyNames |
suspendDynamics |
| getReactionForce |
----------
|
|
Inherited
Variables: |
| mass |
position |
| name |
scaling |
| orientation |
timeOffset |
| parent |
visible |
|
|
boxInsideFrusturm
boxInsideFrusturm(box)
Tests the given box against the view frustum
Returns: INSIDE, OUTSIDE or INTERSECT
box:
Type: a
matrix (float values)
Sample
Code
# get the active camera
cam = GameLogic.getCurrentScene().active_camera
################ Box to test
# create an empty array
box = [ ]
# enter the position of the corner vertices
box.append([ -1.0, -1.0, -1.0])
box.append([ -1.0, -1.0, 1.0])
box.append([ -1.0, 1.0, -1.0])
box.append([ -1.0, 1.0, 1.0])
box.append([ 1.0, -1.0, -1.0])
box.append([ 1.0, -1.0, 1.0])
box.append([ 1.0, 1.0, -1.0])
box.append([ 1.0, 1.0, 1.0])
# camera inside box?
if cam.boxInsideFrustum(box) != cam.OUTSIDE:
# box is inside
# your code here
else:
# box is outside
# your code here
enableViewport
enableViewport(enable)
enable/disable viewport. For more information, see
setViewport function below.
enable:
Type:
Bool (True or false. 1 or 0)
Sample
Code
# need to get game window size so...
import Rasterizer
# get list of objects in scene
objList = GameLogic.getCurrentScene().getObjectList()
# get 2nd camera named "ViewPort"
viewCam = objList["OBViewPort"]
# set split screen
viewCam.setViewport( 0,
Rasterizer.getWindowHeight()/2,
Rasterizer.getWindowWidth(),
Rasterizer.getWindowHeight() )
# use viewCam to create split screen
viewCam.enableViewport(True)
getCameraToWorld
getCameraToWorld()
Returns the camera to world transform
Return type: 4x4 matrix.
Sample
Code
# get the active camera
cam = GameLogic.getCurrentScene().active_camera
# get transform
transform = cam.getCameraToWorld()
getProjectionMatrix
getProjectionMatrix()
Returns the camera projection matrix
Return type: 4x4 matrix.
Sample
Code
# get the active camera
cam = GameLogic.getCurrentScene().active_camera
# get projection matrix
matrix = cam.getProjectionMatrix()
getWorldToCamera
getWorldToCamera()
Returns the world to camera transform (which is the inverse matrix of
the camera to world transform)
Return type: 4x4 matrix.
Sample
Code
# get the active camera
cam = GameLogic.getCurrentScene().active_camera
# get transform
transform = cam.getWorldToCamera()
pointInsideFrustum
pointInsideFrustum(point)
Tests whether or not a point is inside the camera view frustum.
Return Type: Bool
True (1) if the
point is inside the view frustum.
False (0) if it isn't.
point:
Type:
list [ x, y, z]
Sample
Code
# get the active camera
cam = GameLogic.getCurrentScene().active_camera
# point inside view frustum
pointInside = cam.pointInsideFrustum( [0.0, 0.0, 0.0])
setOnTop
setOnTop()
Sets this camera's viewport on top
Note:
The camera's viewport must be enabled.
See enableViewport function above
Sample
Code
# get controller
controller = GameLogic.getCurrentController()
# get camera that controller is attached to
cam = controller.getOwner()
# set camera's viewport on top of the other enabled
viewports
cam.setOnTop()
setProjectionMatrix
setProjectionMatrix(matrix)
Sets the camera projection matrix
matrix:
Type is 4x4 Matrix
Sample
Code
# get the active camera
cam = GameLogic.getCurrentScene().active_camera
# your four by four matrix
matrix = [ your four by four matrix here]
# set projection matrix
cam.setProjectionMatrix(matrix)
setViewport
setViewport( left, bottom, right, top)
setViewport allows you to display more than one camera view in the game
window at the same time.
left
Type:
integer
bottom
Type:
integer
right
Type:
integer
top
Type:
integer
Note:
left, bottom, right and top aren't the positions of the
corner vertices. They are the positions of the sides
Sample Code
# Create a rear view mirror
# need to get game window size so...
import Rasterizer
# get current scene
scene = GameLogic.getCurrentScene()
# get list of objects in scene
objList = scene.getObjectList()
# get 2nd camera named "RearView"
viewCam = objList["OBRearView"]
# set the sides of the rear view mirror
left = Rasterizer.getWindowWidth() * 1/4
bottom = Rasterizer.getWindowHeight() * 3/4
right = Rasterizer.getWindowWidth() * 3/4
top = Rasterizer.getWindowHeight() * 95/100
# set picture in picture size
viewCam.setViewport( left, bottom, right, top)
# use rear view mirror
viewCam.enableViewport(True)
sphereInsideFrustum
sphereInsideFrustum(centre, radius)
Checks to see if a sphere is inside the camera's view frustum.
Returns: INSIDE, OUTSIDE or INTERSECT
center:
Type: List
[ x, y, z]
Center of the sphere in World Coordinates.
radius:
Type:
float number.
Radius of the sphere
Sample Code
# get the active camera
cam = GameLogic.getCurrentScene().active_camera
# check if sphere is inside view frustum
sphereInside = cam.sphereInsideFrustum( [0.0, 0.0, 0.0], 4.5)
if sphereInside == cam.INSIDE:
# your code here
if sphereInside == cam.OUTSIDE:
# your code here
if sphereInside == cam.INTERSECT:
# your code here
camera_to_world
camera_to_world
Returns the camera to world transform
Type: 4x4 matrix.
Sample Code
# get the active camera
cam = GameLogic.getCurrentScene().active_camera
# get transform
transform = cam.camera_to_world
far
far
Returns/Sets the camera's far clip distance
Type: float
Sample Code
# get the active camera
cam = GameLogic.getCurrentScene().active_camera
# get far clipping distance
farClip = cam.far
# set the clipping distance to 500
cam.far = 500.0
frustum_culling
frustum_culling
Returns/Sets whether or not camera is frustum culling.
Type: bool
True or False
1 or 0
Sample Code
# get the active camera
cam = GameLogic.getCurrentScene().active_camera
# get frustum culling
culling = cam.frustum_culling
# set it to False
cam.frustum_culling = False
lens
lens
Returns/Sets the camera's lens value.
Type: float
Sample Code
# get the active camera
cam = GameLogic.getCurrentScene().active_camera
# get lens
lens = cam.lens
# set lens to 100
cam.lens = 100.0
modelview_matrix
modelview_matrix
Returns the camera's 4x4 model view matrix
Type: 4x4 matrix.
Sample Code
# get the active camera
cam = GameLogic.getCurrentScene().active_camera
# get matrix
matrix = cam.modelview_matrix
near
near
Return/Set the camera's near clip distance
Type: float
Sample Code
# get the active camera
cam = GameLogic.getCurrentScene().active_camera
# get near clipping distance
nearClip = cam.near
# set the clipping distance to 5
cam.near = 5.0
perspective
perspective
Return/Set whether or not camera is using a perspective transform
Type: Bool
True or False
1 or 0
Sample Code
# get the active camera
cam = GameLogic.getCurrentScene().active_camera
# camera using perspective view?
perspective = cam.perspective
# set camera to orthographic view
cam.perspective = False
projection_matrix
projection_matrix
Return camera's 4x4 projection matrix
Type: 4 x 4 matrix
Sample Code
# get the active camera
cam = GameLogic.getCurrentScene().active_camera
# get projection matrix
matrix = cam.projection_matrix
# your four by four matrix
matrix = [ your four by four matrix here]
# set projection matrix
cam.projection_matrix = matrix
world_to_camera
world_to_camera
Returns camera's world to camera transform
Type: 4x4 matrix.
Sample Code
# get the active camera
cam = GameLogic.getCurrentScene().active_camera
# get transform
transform = cam.world_to_camera
INSIDE
a return value for
sphereInsideFrustum() and boxInsideFrustum()
INTERSECT
a return value for
sphereInsideFrustum() and boxInsideFrustum()
OUTSIDE
a return value for
sphereInsideFrustum() and boxInsideFrustum()

alignAxisToVect
alignAxisToVect(vect, axis, fac)
Aligns a Game Object axis to a World vector.
vect:
Type:
float List
Uses the World axis
as it's reference.
(World x-axis = [ 1.0, 0.0, 0.0]
World y-axis = [ 0.0, 1.0, 0.0]
World z-axis = [ 0.0, 0.0, 1.0] )
axis:
Type:
integer
0 = Game Object
x-axis
1 = Game Object y-axis
2 = Game Object z-axis
fac:
Determines the
"speed" of the alignment.
Type: float
Range: 0.0 to 1.0
Sample Code
# get controller
controller = GameLogic.getCurrentController()
# get object that controller is attached to
owner = controller.getOwner()
# align object x-axis to world x-axis
owner.alignAxisToVect([1.0,0.0,0.0], 0, 1.0)
# align object y-axis to world y-axis
owner.alignAxisToVect([0.0,1.0,0.0], 1, 1.0)
# align object z-axis to world z-axis
owner.alignAxisToVect([0.0,0.0,1.0], 2, 1.0)
Note:
While I am aligning the Game object axis to a World
axis, you can align the Game Object axis to any vector.
Note:
The values of the vector are the cosine of the angles.
applyImpulse
applyImpulse( point, impulse)
Applies an impluse to the game object point you choose.
point:
Type: list
[ x, y, z]
impulse
Type: list
[ fx, fy, fz]
Note:
Actor with Dynamics must be enabled.
Sample Code
# get controller
controller = GameLogic.getCurrentController()
# get object that controller is attached to
owner = controller.getOwner()
# apply impluse to object center
point = [ 0.0, 0.0, 0.0]
# impulse to be applied to Z axis
impulse = [ 0.0, 0.0, 10.0]
# apply impulse
owner.applyImpulse( point, impulse)
disableRigidBody
disableRigidBody()
Turns off rigid body for that object. (Rigid body lets
objects roll on impact.)
Note:
Doesn't work with Bullet.
Sample Code
# get a list of the objects in the scene
objList = GameLogic.getCurrentScene().getObjectList()
# get camera named Camera
cam = objList["OBCamera"]
# turn off rigid body
cam.disableRigidBody()
enableRigidBody
enableRigidBody()
Enables rigid body for this object. (Rigid body let's objects roll on
impact.)
Note:
Doesn't work with Bullet.
Sample Code
# get a list of the objects in the scene
objList = GameLogic.getCurrentScene().getObjectList()
# get camera named Camera
cam = objList["OBCamera"]
# enable rigid body
cam.enableRigidBody()
endObject
endObject()
Removes a Game Object.
Sample Code
# get a list of the objects in the scene
objList = GameLogic.getCurrentScene().getObjectList()
# get Crate
crate = objList["OBCrate"]
# remove Crate from game
crate.endObject()
getAngularVelocity
getAngularVelocity(local)
Returns the angular velocity of the object center using either the
World axis or the Game Object axis.
local:
Type: Bool
True or 1 = Game Object axis
False or 0 = World axis
Return Type:
List [ x, y ,z]
x = float (angular
velocity around x-axis)
y = float (angular velocity around y-axis)
z = float (angular velocity around z-axis)
Sample Code
# get the controller
controller = GameLogic.getCurrentController()
# get the game object controller attached to
owner = controller.getOwner()
# get angular velocity around game object axis
angVel = owner.getAngularVelocity(True)
getAxisVect
getAxisVect(worldVec)
Returns the alignment of the Game Object x, y and z axis to a World
vector.
Return type: List float [ object x-axis, object y-axis,
object z-axis]
example:
[0.634, 0.773, 0.0]
worldVec:
Type: List
float
Uses the World axis as it's reference.
(World x-axis = [ 1.0, 0.0, 0.0]
World y-axis = [ 0.0, 1.0, 0.0]
World z-axis = [ 0.0, 0.0, 1.0] )
Note:
The values of the vector are the cosine of the angles.
Sample Code
# get the controller
controller = GameLogic.getCurrentController()
# get the game object controller attached to
owner = controller.getOwner()
# get owner's alignment to the World x-axis
vect = owner.getAxisVect( [1.0, 0.0, 0.0])
Note:
While
I am getting the alignment the Game Object axis to a World axis, you
can get the alignment of the Game Object axis to any vector.
getChildren
getChildren()
Returns a list of the Game Object(s) that are the children of an
Object.
Return type: list [ KX_GameObject ]
Sample Code
# get the controller
controller = GameLogic.getCurrentController()
# get the parent the controller is attached to
parent = controller.getOwner()
# get a list of the children game objects
childList = owner.getChildren()
# get the name of first game object in the list
name = childList[0].name
getChildrenRecursive
getChildrenRecursive()
Returns a list of the Game Object(s) that are the children and children
of the children. (ie. children and grandchildren.)
Return type: list [ KX_GameObject ]
Sample Code
# get the controller
controller = GameLogic.getCurrentController()
# get the parent the controller is attached to
parent = controller.getOwner()
# get a list of the children and 'grandchildren' game
objects
childList = owner.getChildrenResursive()
# get the name of first game object in the list
name = childList[0].name
getDistanceTo
getDistanceTo(other)
Returns the distance between 2 objects/points. No x , y
or z values. Just the distance.
Return type: float
other:
Type:
KX_GameObject ( a game object)
or
list [ x, y, z] (a point)
Sample Code
# get the controller
controller = GameLogic.getCurrentController()
# get the game object that the controller is attached
to.
owner = controller.getOwner()
# get object named Box
box = objList["OBBox"]
# get the distance between them
distance = owner.getDistanceTo(box)
getLinearVelocity
getLinearVelocity(local)
Returns an object center's linear speed.
local:
Local or world
velocity
Type: Bool
1 or True = Local velocity
0 or False = World velocity
Return type: float list [ x, y, z]
Note:
Linear Velocity uses physics. Use Actor with
Dynamics must be enabled.
Sample Code
# get the controller
controller = GameLogic.getCurrentController()
# get the game object that the controller is attached
to.
owner = controller.getOwner()
# get local (game object) linear velocity
linVelocity = owner.getLinearVelocity(True)
getMass
getMass()
Returns the object's mass
Return type: float value
Note:
Actor with Dynamics must be enabled.
Sample Code
# get the controller
controller = GameLogic.getCurrentController()
# get the game object that the controller is attached
to.
owner = controller.getOwner()
# get mass
mass = owner.getMass()
getMesh
getMesh(mesh)
Returns mesh object.
Returns the value None if the object doesn't have a mesh.
Return type: mesh object
mesh:
Type:
integer
0 is the first mesh of the object.
1 is the second.
Etc.
(Default is 0)
Sample Code
# get the controller
controller = GameLogic.getCurrentController()
# get the game object that the controller is attached
to.
owner = controller.getOwner()
# get the first mesh object
mesh = owner.getMesh(0)
getOrientation
getOrientation()
Returns the object's orientation.
Return type: 3x3 matrix.
Sample Code
# get the controller
controller = GameLogic.getCurrentController()
# get the game object that the controller is attached
to.
owner = controller.getOwner()
# get owner orientation to match world orientation
orientation = owner.getOrientation()
getParent
getParent()
Returns the parent of the object.
Returns the value None if there isn't a parent
Return type: KX_GameObject
Sample Code
# get the controller
controller = GameLogic.getCurrentController()
# get the game object that the controller is attached
to.
owner = controller.getOwner()
# get the parent
parent = owner.getParent()
getPhysicsId
getPhysicsId()
Returns the ID number of the object's physics controller.
Return type: integer
Note:
Actor with Dynamics must be enabled.
Sample Code
# get the controller
controller = GameLogic.getCurrentController()
# get the game object that the controller is attached
to.
owner = controller.getOwner()
# get the object's physics ID
physicsID = owner.getPhysicsId()
getPosition
getPosition()
Returns the object's position using x, y and z world coordinates.
Return type: list [ x, y, z]
Sample Code
# get the controller
controller = GameLogic.getCurrentController()
# get the game object that the controller is attached
to.
owner = controller.getOwner()
# get it's position
pos = owner.getPosition()
getPropertyNames
getPropertyNames()
Returns a list of the names of the properties (variables) you attached
to the object.
Return type: list [string]
Sample Code
# get controller
controller = GameLogic.getCurrentController()
# get object that controller is attached to
owner = controller.getOwner()
# get a list of the property names
propNames = owner.getPropertyNames()
getReactionForce
getReactionForce()
Returns the force applied to the object over the last simulation
timestep (includes reaction force from collisions)
Return type: list [fx, fy, fz]
Note:
Actor with Dynamics must be enabled.
Sample Code
# get controller
controller = GameLogic.getCurrentController()
# get object that controller is attached to
owner = controller.getOwner()
# get the reaction force
reactionForce = owner.getReactionForce()
getState
getState()
Returns the sum of the active State Mask groups
Return Type: interger
1 = State Mask
group 1 active
2 = State Mask group 2 active
3 = State Mask groups 2 and 1active
4 = State Mask group 3 active
5 = State Mask groups 3 and 1 active
6 = State Mask groups 3 and 2 active
7 = State Mask groups 3 and 2 and 1 active
8 = State Mask group 4 active
etc
16 = layer 5
etc
32 = layer 6
etc.
Sample Code
# get controller
controller = GameLogic.getCurrentController()
# get object that controller is attached to
owner = controller.getOwner()
# get the sum of the active state mask groups
activeStates = owner.getState()
getVectTo
getVectTo(pos)
Returns a vector (using the world axis) to a game object or a point.
Return type: list [ xVec, yVec, zVec ]
pos:
Type:
KX_GameObject
or
point (world coordinates -- example [ 2.0, 3.2,
5.0])
Sample Code
# get the controller
controller = GameLogic.getCurrentController()
# get game object controller attached to
owner = controller.getOwner()
# get a list of the game objects
objList = GameLogic.getCurrentScene().getObjectList()
# get game object named "Box"
box = objList["OBBox"]
# get the vector to box
vectTo = owner.getVectTo(box)
getVelocity
getVelocity(point)
Returns the game object's velocity at the specified point on the
object, including angular components.
Return type: list [vx, vy, vz]
point:
Type:
float list [x,y,z]
Uses local coordinates.
Object center is default ( [ 0.0, 0.0, 0,0])
Sample Code
# get controller
controller = GameLogic.getCurrentController()
# get object controller attached to
owner = controller.getOwner()
# get velocity of point 2.5 blender units (x-axis) from
object center
pointVel = owner.getVelocity([2.5, 0.0, 0.0])
getVisible
getVisible()
Returns if the Game Object is visible or invisible.
Return type: bool
1 = True = Game
Object is visible
0 = False = Game Object is invisible
Sample Code
# get the controller
controller = GameLogic.getCurrentController()
# get object that controller is attached to
owner = controller.getOwner()
# find out if object is visible or invisible
vis = owner.getVisible()
rayCast
rayCast(to, from, distance, property)
to:
Game object or a
position
Type:
KX_GameObject
or
Position [ x, y, z ] World
coordinates.
from:
Starting point of
the ray.
Type: KX_GameObject
or
Position [ x, y, z ] World
coordinates.
distance:
Length of the ray.
Type: Blender units
Notes:
0 or (0.0) = ray stretches all the way to the other
object center or position.
Can be negative (look behind the object rayCast is
attached to).
Can be greater than other if "to" is a position and not a Game Object.
property:
Property on an
object that triggers the ray.
Note:
An empty string ("") = all properties trigger ray
Returns the Game object that was hit, the position of the hit and the
angle of the hit.
Returns type: list [
GameObject, hit, normal]
GameObject:
The game object that
triggered the ray.
Type: a
KX_GameObject
hit:
The position of the
hit. (The distance from the object center of the game object.)
Type: float List [ x, y, z]
normal:
The normal of the
surface that the ray hit. (The angle of the hit.)
Type: float list [ x vector, y vector, z vector]
Note:
Returns [ None, None, None] if nothing was hit.
Sample Code
# get controller rayCast is attached to
controller = GameLogic.getCurrentController()
# get game object rayCast is attached
owner = controller.getOwner()
# get a list of the objects in the scene
objList = GameLogic.getCurrentScene().getObjectList()
# get the object named Cube that rayCast is pointing at
cube = objList["OBCube"]
# get GameObject, hit position and angle.
hit = owner.rayCast( cube, owner, 0.0, "blueTeam")
rayCastTo
rayCastTo(other, disance, property)
Returns the KX_GameObject that trips rayCastTo. (Acts like a laser beam
trip wire between one object and an object/position.)
other:
This is the
object/position the trip wire stretches towards.
Type: KX_GameObject (object center)
or
a position ( [x, y, z]) float
values.
distance:
This is the length
of your trip wire.
Type: float or integer
Notes:
0 or (0.0) = ray stretches all the way to the other
object center or position.
Can be negative (look behind the object rayCastTo is attached to).
Can be greater than other if "to" is a position and not a Game Object.
property:
Type:
String
Property that the trip wire looks for.
Note:
An empty string ("") = all properties trigger ray
Returns:
Return
Type: KX_GameObject
Returns None if it doesn't find anything.
Sample Code
# get controller rayCastTo is attached to
controller = GameLogic.getCurrentController()
# get game object rayCastTo is attached to
owner = controller.getOwner()
# get a list of the objects in the scene
objList = GameLogic.getCurrentScene().getObjectList()
# get the object named Cube that rayCastTo is pointing
at
cube = objList["OBCube"]
# set a trip wire between owner and cube
tripped = owner.rayCastTo(cube, 0, "blueTeam")
# get the name of the game object that triggered the
trip wire
if tripped != None:
name = tripped.name
removeParent
removeParent()
Removes the parent.
Sample Code
# get controller
controller = GameLogic.getCurrentController()
# get game object controller is attached to
owner = controller.getOwner()
# remove parent
owner.removeParent()
restoreDynamics
restoreDynamics()
Restores the dynamics after they have been suspended.
Note:
Actor with Dynamics must be enabled.
Sample Code
# get the controller
controller = GameLogic.getCurrentController()
# get game object controller attached to
owner = controller.getOwner()
# restore dynamics
owner.restoreDynamics()
setAngularVelocity
setAngularVelocity(angVel, local)
Sets the angular velocity around the Game Object object center.
Uses either local or world axis.
angVel:
Type: float list [
xAngVel, yAngVel, zAngVel]
xAngVel = angular velocity around the x-axis
yAngVel = angular velocity around the y-axis
zAngVel = angular velocity around the z-axis
local:
Type: bool
1 or True
= local (game object) axis
0 or False = world axis
Sample Code
# get controller
controller = GameLogic.getCurrentController()
# get game object controller is attached to
owner = controller.getOwner()
# set angular velocity around local z-axis
owner.setAngularVelocity([0.0, 0.0, 2.0], True)
setCollisionMargin
setCollisionMargin(margin)
Sets the collision margin of an object in physics simulations.
margin:
Type:
float
Note:
The default margin is 0.06.
Note:
Actor with Dynamics must be enabled.
Sample Code
# get the controller
controller = GameLogic.getCurrentController()
# get game object controller attached to
owner = controller.getOwner()
# set collision margin
owner.setCollisionMargin(0.1)
setLinearVelocity
setLinearVelocity(force, local)
Sets the linear velocity of a game object.
force:
Force to be applied
along an axis.
Type: float list [fx, fy, fz]
local:
Select local or
world axis to apply force.
Type: Bool
1 or True = use local (game object) axis
0 or False = use world axis
Note:
Actor with Dynamics must be enabled.
Sample Code
# get controller
controller = GameLogic.getCurrentController()
# get game object controller is attached to
owner = controller.getOwner()
# apply a force of 5.0 to game object (local) x-axis
owner.setLinearVelocity([5.0, 0.0, 0.0], True)
setOrientation
setOrientation(orn)
Sets the object's orientation.
orn
Type: 3x3
matrix.
Sample Code
# get controller
controller = GameLogic.getCurrentController()
# get game object controller is attached to
owner = controller.getOwner()
# set owner orientation to match world orientation
owner.setOrientation([1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0])
setParent
setParent(parent)
Parents the object to another object.
parent
Type:
KX_GameObject
Sample Code
# get a list of the objects in the scene
objList = GameLogic.getCurrentScene().getObjectList()
# get the object named Cube from the list
cube = objList["OBCube"]
# get the object named Suzanne
suz = objList["OBSuzanne"]
# make cube a child of suz
cube.setParent(suz)
setPosition
setPosition(pos)
Sets the object's position using X, Y and Z World coordinates.
pos
Type:
list [ x, y, z]
Sample Code
# get controller
controller = GameLogic.getCurrentController()
# get game object controller is attached to
owner = controller.getOwner()
# move it to new position
owner.setPosition([ 10.0, 5.0, 1.0])
setState
setState(sum)
Sets the active State Mask groups
sum:
Type:
interger
1 = State Mask group
1 active
2 = State Mask group 2 active
3 = State Mask groups 2 and 1active
4 = State Mask group 3 active
5 = State Mask groups 3 and 1 active
6 = State Mask groups 3 and 2 active
7 = State Mask groups 3 and 2 and 1 active
8 = State Mask group 4 active
etc
16 = layer 5
etc
32 = layer 6
etc.
Sample Code
# get controller
controller = GameLogic.getCurrentController()
# get object that controller is attached to
owner = controller.getOwner()
# make state mask group 1 active
owner.setState(1)
setVisible
setVisible(visible)
Makes the object visible or invisible. Doesn't remove
it. It is still there.
visible:
Type:
bool
True or 1 = make visible
False or 0 = make invisible
Sample Code
# get controller
controller = GameLogic.getCurrentController()
# get object that controller is attached to
owner = controller.getOwner()
# make it invisible
owner.setVisible(False)
setWorldPosition
setWorldPosition(pos)
Sets the world position.
pos:
Type:
float list [xPos, yPos, zPos]
Sample Code
# get controller
controller = GameLogic.getCurrentController()
# get game object controller is attached to
owner = controller.getOwner()
# move game object to world [5.0, 0.0, 0.0]
owner.setWorldPosition([5.0, 0.0, 0.0])
suspendDynamics
suspendDynamics()
Turns off the Dynamics on an object.
Note:
Actor with Dynamics must be enabled.
Sample Code
# get controller
controller = GameLogic.getCurrentController()
# get game object controller is attached to
owner = controller.getOwner()
# disable dynamics
owner.suspendDynamics()
mass
mass
Returns game object's mass
Type: float.
Note:
Actor with Dynamics must be enabled.
Sample Code
# get controller
controller = GameLogic.getCurrentController()
# get game object controller is attached to
owner = controller.getOwner()
# get mass
mass = owner.mass
name
name
Returns/Sets the object's name
Type: string
Sample Code
# get controller
controller = GameLogic.getCurrentController()
# get game object controller is attached to
owner = controller.getOwner()
# get object name
name = owner.name
# name it Fred
owner.name = "Fred"
orientation
orientation
Returns/Sets the object's orientation.
Type: 3x3 matrix
Sample Code
# get controller
controller = GameLogic.getCurrentController()
# get game object controller is attached to
owner = controller.getOwner()
# get orientation
orient = owner.orientation
# align light orientation to world orientation
owner.orientation = [[ 1.0, 0.0, 0.0], [ 0.0, 1.0, 0.0], [ 0.0, 0.0,
1.0]]
parent
parent
Returns the parent object.
Returns 'None' if there isn't a parent.
Type: KX_GameObject
Sample Code
# get controller
controller = GameLogic.getCurrentController()
# get game object controller is attached to
owner = controller.getOwner()
# get parent object
parent = owner.parent
# What the heck. Let's get the parent's name
while we're at it
name = parent.name
position
position
Returns/Sets the object's position.
Type: list [ x, y, z]
Sample Code
# get controller
controller = GameLogic.getCurrentController()
# get game object controller is attached to
owner = controller.getOwner()
# get position
pos = owner.position
# Reset position to [0,0,0]
owner.position = [0.0, 0.0, 0.0]
scaling
scaling
Returns/Sets a game object's scale
Type: float list [scaleX, scaleY, scaleZ]
Sample Code
# get controller
controller = GameLogic.getCurrentController()
# get object that controller is attached to
owner = controller.getOwner()
# get owner's x,y and z scale
scale = owner.scaling
# Set scale to [2.0,2.0,2.0]
owner.scaling = [2.0, 2.0, 2.0]
timeOffset
timeOffset
Sets/Returns:
Amount of time the
child's reaction is offset from the parent.
Type: float
Note:
SlowPar button must be enabled (on the Child object)
Buttons Window menu >> Object (F7)
>> Object buttons
Anim settings tab >> SlowPar button
Note:
Object must be parented to another object.
Note:
Crashes Blender if there isn't a parent.
Note:
Doesn't work with the Parent Actuator.
Parent with Ctrl P
Sample Code
# get controller
controller = GameLogic.getCurrentController()
# get child that controller is attached to
child = controller.getOwner()
# get time offset
delay = child.timeOffset
# set the time offset
child.timeOffset = 500.00
visible
visible
Returns/Sets a game object's visibility
Type: bool
True or False. Also 1 or 0
Sample Code
# get controller
controller = GameLogic.getCurrentController()
# get game object controller is attached to
owner = controller.getOwner()
# get visibility status
visibleStatus = owner.visible
# Make it invisible
owner.visible = False
isA
isA(Type)
Checks the Object type.
(KX_GameObject,
SCA_ILogicBrick, KX_Scene, etc.)
Type: String
Return Type: Bool
1 = True
0 = False
Sample Code
# get the controller
controller = GameLogic.getCurrentController()
# get the object controller attached to
owner = controller.getOwner()
# is owner a GameObject?
gameObject = owner.isA("KX_GameObject")
getName
getName()
Returns the name of actuator
Return Type: string
Sample Code
# get the controller
controller = GameLogic.getCurrentController()
# get a list of the attached actuators
actList = controller.getActuators()
# loop through the list of actuators
for act in actList:
# look for an
actuator named "RocketMotion"
if act.getName() ==
"RocketMotion":
# use it
GameLogic.addActiveActuator(act,
True)
# Done.
Break out of loop
break
|