| 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 |
----------
|
|
| Variables: |
| mass |
position |
| name |
scaling |
| orientation |
timeOffset |
| parent |
visible |
|
|
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 rotate.)
Note:
Doesn't work with Bullet.
Sample Code
# get controller
controller = GameLogic.getCurrentController()
# get object that controller is attached to
owner = controller.getOwner()
# turn off rigid body
owner.disableRigidBody()
enableRigidBody
enableRigidBody()
Enables rigid body for this object. (Rigid body let's objects rotate.)
Note:
Doesn't work with Bullet.
Sample Code
# get controller
controller = GameLogic.getCurrentController()
# get object that controller is attached to
owner = controller.getOwner()
# enable rigid body
owner.enableRigidBody()
endObject
endObject()
Removes a Game Object.
Sample Code
# get controller
controller = GameLogic.getCurrentController()
# get object that controller is attached to
owner = controller.getOwner()
# remove owner from game
owner.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 a list of the objects in the sceneobjList = GameLogic.getCurrentScene().getObjectList()
# 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 the distance and vector to a game object or a point.
pos:
Type:
KX_GameObject
or
point (world coordinates -- example [ 2.0, 3.2,
5.0])
Return type: list [ distance, globalVector, localVector ] distance: distance to the game object or point Type: float
globalVector: Vector to object/point using the global axis Type: list[vx, vy, vz]
vx = cosine of the angle of the vector to the global x axis plane vy = cosine of the angle of the vector to the global y axis plane vz = cosine of the angle of the vector to the global z axis plane
localVector: Vector to object/point using the local (game object) axis Type: list[vx, vy, vz] vx = cosine of the angle of the vector to the local x axis plane vy = cosine of the angle of the vector to the local y axis plane vz = cosine of the angle of the vector to the local z axis plane
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 distance and 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
|