Module KX_GameObject :: Class KX_GameObject

Class KX_GameObject

source code

Known Subclasses:
KX_Camera.KX_Camera, KX_Light.KX_Light

All game objects are derived from this class.

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

Instance Methods
 
applyImpulse(point, impulse)
Applies an impulse to the game object.
source code
 
disableRigidBody()
Disables rigid body physics for this object.
source code
 
enableRigidBody()
Enables rigid body physics for this object.
source code
float
getDistanceTo(other)
Returns the distance to another object or point.
source code
list [vx, vy, vz]
getLinearVelocity(local)
Gets the game object's linear velocity.
source code
float
getMass()
Gets the game object's mass.
source code
KX_MeshProxy
getMesh(mesh)
Gets the mesh object for this object.
source code
3x3 rotation matrix
getOrientation()
Gets the game object's orientation.
source code
KX_GameObject
getParent()
Gets this object's parent.
source code
 
getPhysicsId()
Returns the user data object associated with this game object's physics controller.
source code
list [x, y, z]
getPosition()
Gets the game object's position.
source code
list [fx, fy, fz]
getReactionForce()
Gets the game object's reaction force.
source code
list [vx, vy, vz]
getVelocity(point)
Gets the game object's velocity at the specified 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
 
removeParent()
Removes this objects parent.
source code
 
restoreDynamics()
Resumes physics for this object.
source code
 
setOrientation(orn)
Sets the game object's orientation.
source code
 
setParent(parent)
Sets this object's parent.
source code
 
setPosition(pos)
Sets the game object's position.
source code
 
setVisible(visible)
Sets the game object's visible flag.
source code
 
suspendDynamics()
Suspends physics for this object.
source code
Instance Variables
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.
boolean visible
visibility flag.
Method Details

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)

enableRigidBody()

source code 

Enables rigid body physics for this object.

Rigid body physics allows the object to roll on collisions.

getDistanceTo(other)

source code 
Returns the distance to another object or point.
Parameters:
Returns: float

getLinearVelocity(local)

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.
    • True: you get the "local" velocity ie: relative to object orientation.
Returns: list [vx, vy, vz]
the object's linear velocity.

getMass()

source code 
Gets the game object's mass.
Returns: float
the object's mass.

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.

getOrientation()

source code 
Gets the game object's orientation.
Returns: 3x3 rotation matrix
The game object's rotation matrix

getParent()

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

getPosition()

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

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.

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.

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.
Parameters:
  • other (KX_GameObject or string) - [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

setOrientation(orn)

source code 
Sets the game object's orientation.
Parameters:
  • orn (3x3 rotation matrix, or Quaternion.) - a rotation matrix specifying the new rotation.

setParent(parent)

source code 
Sets this object's parent.
Parameters:

setPosition(pos)

source code 
Sets the game object's position.
Parameters:
  • pos ([x, y, z]) - the new position, in world coordinates.

setVisible(visible)

source code 
Sets the game object's visible flag.

Instance Variable Details

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]