Module KX_GameObject :: Class KX_GameObject
[hide private]
[frames] | no frames]

Class KX_GameObject

source code

Known Subclasses:

All game objects are derived from this class.

Properties assigned to game objects are accessible as attributes of this class.

Instance Methods [hide private]
 
endObject(visible)
Delete this object, can be used inpace of the EndObject Actuator.
source code
boolean
getVisible()
Gets the game object's visible flag.
source code
 
setVisible(visible)
Sets the game object's visible flag.
source code
int
getState()
Gets the game object's state bitmask.
source code
 
setState(state)
Sets the game object's state flag.
source code
 
setPosition(pos)
Sets the game object's position.
source code
 
setWorldPosition(pos)
Sets the game object's position in world coordinates regardless if the object is root or child.
source code
list [x, y, z]
getPosition()
Gets the game object's position.
source code
 
setOrientation(orn)
Sets the game object's orientation.
source code
 
alignAxisToVect(vect, axis)
Aligns any of the game object's axis along the given vector.
source code
3d vector.
getAxisVect(vect)
Returns the axis vector rotates by the objects worldspace orientation.
source code
3x3 rotation matrix
getOrientation()
Gets the game object's orientation.
source code
list [vx, vy, vz]
getLinearVelocity(local=0)
Gets the game object's linear velocity.
source code
 
setLinearVelocity(velocity, local=0)
Sets the game object's linear velocity.
source code
list [vx, vy, vz]
getAngularVelocity(local=0)
Gets the game object's angular velocity.
source code
 
setAngularVelocity(velocity, local=0)
Sets the game object's angular velocity.
source code
list [vx, vy, vz]
getVelocity(point)
Gets the game object's velocity at the specified point.
source code
float
getMass()
Gets the game object's mass.
source code
list [fx, fy, fz]
getReactionForce()
Gets the game object's reaction force.
source code
 
applyImpulse(point, impulse)
Applies an impulse to the game object.
source code
 
suspendDynamics()
Suspends physics for this object.
source code
 
restoreDynamics()
Resumes physics for this object.
source code
 
enableRigidBody()
Enables rigid body physics for this object.
source code
 
disableRigidBody()
Disables rigid body physics for this object.
source code
KX_GameObject
getParent()
Gets this object's parent.
source code
 
setParent(parent)
Sets this object's parent.
source code
 
removeParent()
Removes this objects parent.
source code
list
getChildren()
Return a list of immediate children of this object.
source code
list
getChildrenRecursive()
Return a list of children of this object, including all their childrens children.
source code
KX_MeshProxy
getMesh(mesh)
Gets the mesh object for this object.
source code
 
getPhysicsId()
Returns the user data object associated with this game object's physics controller.
source code
list
getPropertyNames()
Gets a list of all property names.
source code
float
getDistanceTo(other)
Returns the distance to another object or point.
source code
3-tuple (float, 3-tuple (x,y,z), 3-tuple (x,y,z))
getVectTo(other)
Returns the vector and the distance to another object or point.
source code
KX_GameObject
rayCastTo(other, dist, prop)
Look towards another point/object and find first object hit within dist that matches prop.
source code
3-tuple (KX_GameObject, 3-tuple (x,y,z), 3-tuple (nx,ny,nz)) or 4-tuple (KX_GameObject, 3-tuple (x,y,z), 3-tuple (nx,ny,nz), KX_PolyProxy)
rayCast(objto, objfrom, dist, prop, face, xray, poly)
Look from a point/object to another point/object and find first object hit within dist that matches prop.
source code
Instance Variables [hide private]
float mass
The object's mass (provided the object has a physics controller).
string. name
The object's name.
3x3 Matrix [[float]] orientation
The object's orientation.
KX_GameObject parent
The object's parent object.
list [x, y, z] position
The object's position.
list [sx, sy, sz] scaling
The object's scaling factor.
float timeOffset
adjust the slowparent delay at runtime.
boolean visible
visibility flag.
Method Details [hide private]

endObject(visible)

source code 

Delete this object, can be used inpace of the EndObject Actuator. The actual removal of the object from the scene is delayed.

setVisible(visible)

source code 

Sets the game object's visible flag.

Parameters:
  • visible (boolean)

getState()

source code 

Gets the game object's state bitmask.

Returns: int
the objects state.

setState(state)

source code 

Sets the game object's state flag. The bitmasks for states from 1 to 30 can be set with (1<<0, 1<<1, 1<<2 ... 1<<29)

Parameters:
  • state (integer)

setPosition(pos)

source code 

Sets the game object's position. Global coordinates for root object, local for child objects.

Parameters:
  • pos ([x, y, z]) - the new position, in local coordinates.

setWorldPosition(pos)

source code 

Sets the game object's position in world coordinates regardless if the object is root or child.

Parameters:
  • pos ([x, y, z]) - the new position, in world coordinates.

getPosition()

source code 

Gets the game object's position.

Returns: list [x, y, z]
the object's position in world coordinates.

setOrientation(orn)

source code 

Sets the game object's orientation.

Parameters:
  • orn (3x3 rotation matrix, or Quaternion.) - a rotation matrix specifying the new rotation.

Note: When using this matrix with Blender.Mathutils.Matrix() types, it will need to be transposed.

alignAxisToVect(vect, axis)

source code 

Aligns any of the game object's axis along the given vector.

Parameters:
  • vect (3d vector.) - a vector to align the axis.
  • axis (integer.) - The axis you want to align
    • 0: X axis
    • 1: Y axis
    • 2: Z axis (default)

getAxisVect(vect)

source code 

Returns the axis vector rotates by the objects worldspace orientation. This is the equivalent if multiplying the vector by the orientation matrix.

Parameters:
  • vect (3d vector.) - a vector to align the axis.
Returns: 3d vector.
The vector in relation to the objects rotation.

getOrientation()

source code 

Gets the game object's orientation.

Returns: 3x3 rotation matrix
The game object's rotation matrix

Note: When using this matrix with Blender.Mathutils.Matrix() types, it will need to be transposed.

getLinearVelocity(local=0)

source code 

Gets the game object's linear velocity.

This method returns the game object's velocity through it's centre of mass, ie no angular velocity component.

Parameters:
  • local (boolean) - - False: you get the "global" velocity ie: relative to world orientation (default).
    • True: you get the "local" velocity ie: relative to object orientation.
Returns: list [vx, vy, vz]
the object's linear velocity.

setLinearVelocity(velocity, local=0)

source code 

Sets the game object's linear velocity.

This method sets game object's velocity through it's centre of mass, ie no angular velocity component.

Parameters:
  • velocity (3d vector.) - linear velocity vector.
  • local (boolean) - - False: you get the "global" velocity ie: relative to world orientation (default).
    • True: you get the "local" velocity ie: relative to object orientation.

getAngularVelocity(local=0)

source code 

Gets the game object's angular velocity.

Parameters:
  • local (boolean) - - False: you get the "global" velocity ie: relative to world orientation (default).
    • True: you get the "local" velocity ie: relative to object orientation.
Returns: list [vx, vy, vz]
the object's angular velocity.

setAngularVelocity(velocity, local=0)

source code 

Sets the game object's angular velocity.

Parameters:
  • velocity (3d vector.) - angular velocity vector.
  • local (boolean) - - False: you get the "global" velocity ie: relative to world orientation (default).
    • True: you get the "local" velocity ie: relative to object orientation.

getVelocity(point)

source code 

Gets the game object's velocity at the specified point.

Gets the game object's velocity at the specified point, including angular components.

Parameters:
  • point (list [x, y, z]) - the point to return the velocity for, in local coordinates. (optional: default = [0, 0, 0])
Returns: list [vx, vy, vz]
the velocity at the specified point.

getMass()

source code 

Gets the game object's mass.

Returns: float
the object's mass.

getReactionForce()

source code 

Gets the game object's reaction force.

The reaction force is the force applied to this object over the last simulation timestep. This also includes impulses, eg from collisions.

Returns: list [fx, fy, fz]
the reaction force of this object.

applyImpulse(point, impulse)

source code 

Applies an impulse to the game object.

This will apply the specified impulse to the game object at the specified point. If point != getPosition(), applyImpulse will also change the object's angular momentum. Otherwise, only linear momentum will change.

Parameters:
  • point (list [x, y, z]) - the point to apply the impulse to (in world coordinates)

restoreDynamics()

source code 

Resumes physics for this object.

Note: The objects linear velocity will be applied from when the dynamics were suspended.

enableRigidBody()

source code 

Enables rigid body physics for this object.

Rigid body physics allows the object to roll on collisions.

Note: This is not working with bullet physics yet.

disableRigidBody()

source code 

Disables rigid body physics for this object.

Note: This is not working with bullet physics yet. The angular is removed but rigid body physics can still rotate it later.

getParent()

source code 

Gets this object's parent.

Returns: KX_GameObject
this object's parent object, or None if this object has no parent.

setParent(parent)

source code 

Sets this object's parent.

Parameters:

getChildren()

source code 

Return a list of immediate children of this object.

Returns: list
a list of all this objects children.

getChildrenRecursive()

source code 

Return a list of children of this object, including all their childrens children.

Returns: list
a list of all this objects children recursivly.

getMesh(mesh)

source code 

Gets the mesh object for this object.

Parameters:
  • mesh (integer) - the mesh object to return (optional: default mesh = 0)
Returns: KX_MeshProxy
the first mesh object associated with this game object, or None if this object has no meshs.

getPropertyNames()

source code 

Gets a list of all property names.

Returns: list
All property names for this object.

getDistanceTo(other)

source code 

Returns the distance to another object or point.

Parameters:
Returns: float

getVectTo(other)

source code 

Returns the vector and the distance to another object or point. The vector is normalized unless the distance is 0, in which a NULL vector is returned.

Parameters:
Returns: 3-tuple (float, 3-tuple (x,y,z), 3-tuple (x,y,z))
(distance, globalVector(3), localVector(3))

rayCastTo(other, dist, prop)

source code 

Look towards another point/object and find first object hit within dist that matches prop.

The ray is always casted from the center of the object, ignoring the object itself. The ray is casted towards the center of another object or an explicit [x,y,z] point. Use rayCast() if you need to retrieve the hit point

Parameters:
  • other (KX_GameObject or 3-tuple) - [x,y,z] or object towards which the ray is casted
  • dist (float) - max distance to look (can be negative => look behind); 0 or omitted => detect up to other
  • prop (string) - property name that object must have; can be omitted => detect any object
Returns: KX_GameObject
the first object hit or None if no object or object does not match prop

rayCast(objto, objfrom, dist, prop, face, xray, poly)

source code 

Look from a point/object to another point/object and find first object hit within dist that matches prop. if poly is 0, returns a 3-tuple with object reference, hit point and hit normal or (None,None,None) if no hit. if poly is 1, returns a 4-tuple with in addition a KX_PolyProxy as 4th element.

Ex:

       # shoot along the axis gun-gunAim (gunAim should be collision-free)
       ob,point,normal = gun.rayCast(gunAim,None,50)
       if ob:
               # hit something

Notes: The ray ignores the object on which the method is called. It is casted from/to object center or explicit [x,y,z] points.

The face paremeter determines the orientation of the normal:

 0 => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
 1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)

The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray. The prop and xray parameters interact as follow:

   prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
   prop off, xray on : idem.
   prop on,  xray off: return closest hit if it matches prop, no hit otherwise.
   prop on,  xray on : return closest hit matching prop or no hit if there is no object matching prop on the full extend of the ray.

The KX_PolyProxy 4th element of the return tuple when poly=1 allows to retrieve information on the polygon hit by the ray. If there is no hit or the hit object is not a static mesh, None is returned as 4th element.

The ray ignores collision-free objects and faces that dont have the collision flag enabled, you can however use ghost objects.

Parameters:
  • objto (KX_GameObject or 3-tuple) - [x,y,z] or object to which the ray is casted
  • objfrom (KX_GameObject or 3-tuple or None) - [x,y,z] or object from which the ray is casted; None or omitted => use self object center
  • dist (float) - max distance to look (can be negative => look behind); 0 or omitted => detect up to to
  • prop (string) - property name that object must have; can be omitted => detect any object
  • face (int) - normal option: 1=>return face normal; 0 or omitted => normal is oriented towards origin
  • xray (int) - X-ray option: 1=>skip objects that don't match prop; 0 or omitted => stop on first object
  • poly (int) - polygon option: 1=>return value is a 4-tuple and the 4th element is a KX_PolyProxy
Returns: 3-tuple (KX_GameObject, 3-tuple (x,y,z), 3-tuple (nx,ny,nz)) or 4-tuple (KX_GameObject, 3-tuple (x,y,z), 3-tuple (nx,ny,nz), KX_PolyProxy)
(object,hitpoint,hitnormal) or (object,hitpoint,hitnormal,polygon) If no hit, returns (None,None,None) or (None,None,None,None) If the object hit is not a static mesh, polygon is None

Instance Variable Details [hide private]

mass

The object's mass (provided the object has a physics controller). Read only.
Type:
float

orientation

The object's orientation. 3x3 Matrix. You can also write a Quaternion or Euler vector.
Type:
3x3 Matrix [[float]]

parent

The object's parent object. (Read only)
Type:
KX_GameObject

scaling

The object's scaling factor. list [sx, sy, sz]
Type:
list [sx, sy, sz]