base class — SCA_IObject
All game objects are derived from this class.
Properties assigned to game objects are accessible as attributes of this class.
Note
Calling ANY method or attribute on an object that has been removed from a scene will raise a SystemError, if an object may have been removed since last accessing it use the invalid attribute to check.
KX_GameObject can be subclassed to extend functionality. For example:
import bge
class CustomGameObject(bge.types.KX_GameObject):
RATE = 0.05
def __init__(self, old_owner):
# "old_owner" can just be ignored. At this point, "self" is
# already the object in the scene, and "old_owner" has been
# destroyed.
# New attributes can be defined - but we could also use a game
# property, like "self['rate']".
self.rate = CustomGameObject.RATE
def update(self):
self.worldPosition.z += self.rate
# switch direction
if self.worldPosition.z > 1.0:
self.rate = -CustomGameObject.RATE
elif self.worldPosition.z < 0.0:
self.rate = CustomGameObject.RATE
# Called first
def mutate(cont):
old_object = cont.owner
mutated_object = CustomGameObject(cont.owner)
# After calling the constructor above, references to the old object
# should not be used.
assert(old_object is not mutated_object)
assert(old_object.invalid)
assert(mutated_object is cont.owner)
# Called later - note we are now working with the mutated object.
def update(cont):
cont.owner.update()
When subclassing objects other than empties and meshes, the specific type should be used - e.g. inherit from BL_ArmatureObject when the object to mutate is an armature.
The object’s name. (read-only).
Type: | string |
---|
The object’s mass
Type: | float |
---|
Note
The object must have a physics controller for the mass to be applied, otherwise the mass value will be returned as 0.0.
Enforces the object keeps moving at a minimum velocity.
Type: | float |
---|
Note
Applies to dynamic and rigid body objects only.
Note
A value of 0.0 disables this option.
Note
While objects are stationary the minimum velocity will not be applied.
Clamp the maximum linear velocity to prevent objects moving beyond a set speed.
Type: | float |
---|
Note
Applies to dynamic and rigid body objects only.
Note
A value of 0.0 disables this option (rather then setting it stationary).
the object’s inertia vector in local coordinates. Read only.
Type: | list [ix, iy, iz] |
---|
The object’s parent object. (read-only).
Type: | KX_GameObject or None |
---|
Returns the list of group members if the object is a group object, otherwise None is returned.
Type: | CListValue of KX_GameObject or None |
---|
Returns the group object that the object belongs to or None if the object is not part of a group.
Type: | KX_GameObject or None |
---|
A list of callables to be run when a collision occurs.
Type: | list |
---|
visibility flag.
Type: | boolean |
---|
Note
Game logic will still run for invisible objects.
Record animation for this object.
Type: | boolean |
---|
The object color of the object. [r, g, b, a]
Type: | mathutils.Vector |
---|
occlusion capability flag.
Type: | boolean |
---|
The object’s position. [x, y, z] On write: local position, on read: world position
Deprecated since version use: localPosition and worldPosition.
Type: | mathutils.Vector |
---|
The object’s orientation. 3x3 Matrix. You can also write a Quaternion or Euler vector. On write: local orientation, on read: world orientation
Deprecated since version use: localOrientation and worldOrientation.
Type: | mathutils.Matrix |
---|
The object’s scaling factor. [sx, sy, sz] On write: local scaling, on read: world scaling
Deprecated since version use: localScale and worldScale.
Type: | mathutils.Vector |
---|
The object’s local orientation. 3x3 Matrix. You can also write a Quaternion or Euler vector.
Type: | mathutils.Matrix |
---|
The object’s world orientation. 3x3 Matrix.
Type: | mathutils.Matrix |
---|
The object’s local scaling factor. [sx, sy, sz]
Type: | mathutils.Vector |
---|
The object’s world scaling factor. [sx, sy, sz]
Type: | mathutils.Vector |
---|
The object’s local position. [x, y, z]
Type: | mathutils.Vector |
---|
The object’s world position. [x, y, z]
Type: | mathutils.Vector |
---|
The object’s local space transform matrix. 4x4 Matrix.
Type: | mathutils.Matrix |
---|
The object’s world space transform matrix. 4x4 Matrix.
Type: | mathutils.Matrix |
---|
The object’s local linear velocity. [x, y, z]
Type: | mathutils.Vector |
---|
The object’s world linear velocity. [x, y, z]
Type: | mathutils.Vector |
---|
The object’s local angular velocity. [x, y, z]
Type: | mathutils.Vector |
---|
The object’s world angular velocity. [x, y, z]
Type: | mathutils.Vector |
---|
adjust the slowparent delay at runtime.
Type: | float |
---|
the game object’s state bitmask, using the first 30 bits, one bit must always be set.
Type: | int |
---|
a list meshes for this object.
Type: | list of KX_MeshProxy |
---|
Note
Most objects use only 1 mesh.
Note
Changes to this list will not update the KX_GameObject.
a sequence of SCA_ISensor objects with string/index lookups and iterator support.
Type: | list |
---|
Note
This attribute is experemental and may be removed (but probably wont be).
Note
Changes to this list will not update the KX_GameObject.
a sequence of SCA_IController objects with string/index lookups and iterator support.
Type: | list of SCA_ISensor |
---|
Note
This attribute is experemental and may be removed (but probably wont be).
Note
Changes to this list will not update the KX_GameObject.
a list of SCA_IActuator with string/index lookups and iterator support.
Type: | list |
---|
Note
This attribute is experemental and may be removed (but probably wont be).
Note
Changes to this list will not update the KX_GameObject.
get the objects internal python attribute dictionary for direct (faster) access.
Type: | dict |
---|
direct children of this object, (read-only).
Type: | CListValue of KX_GameObject‘s |
---|
all children of this object including childrens children, (read-only).
Type: | CListValue of KX_GameObject‘s |
---|
The number of seconds until the object ends, assumes 50fps. (when added with an add object actuator), (read-only).
Type: | float |
---|
Delete this object, can be used in place of the EndObject Actuator.
The actual removal of the object from the scene is delayed.
Replace the mesh of this object with a new mesh. This works the same was as the actuator.
Parameters: |
|
---|
Sets the game object’s visible flag.
Parameters: |
|
---|
Sets the game object’s occlusion capability.
Parameters: |
|
---|
Aligns any of the game object’s axis along the given vector.
Parameters: |
|
---|
Returns the axis vector rotates by the objects worldspace orientation. This is the equivalent of multiplying the vector by the orientation matrix.
Parameters: | vect (3D Vector) – a vector to align the axis. |
---|---|
Returns: | The vector in relation to the objects rotation. |
Return type: | 3d vector. |
Sets the game object’s movement.
Parameters: |
|
---|
Sets the game object’s rotation.
Parameters: |
|
---|
Sets the game object’s force.
This requires a dynamic object.
Parameters: |
|
---|
Sets the game object’s torque.
This requires a dynamic object.
Parameters: |
|
---|
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) –
|
---|---|
Returns: | the object’s linear velocity. |
Return type: | list [vx, vy, vz] |
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.
This requires a dynamic object.
Parameters: |
|
---|
Gets the game object’s angular velocity.
Parameters: | local (boolean) –
|
---|---|
Returns: | the object’s angular velocity. |
Return type: | list [vx, vy, vz] |
Sets the game object’s angular velocity.
This requires a dynamic object.
Parameters: |
|
---|
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 (3D Vector) – optional point to return the velocity for, in local coordinates. |
---|---|
Returns: | the velocity at the specified point. |
Return type: | list [vx, vy, vz] |
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: | the reaction force of this object. |
---|---|
Return type: | list [fx, fy, fz] |
Note
This is not implimented at the moment.
Applies an impulse to the game object.
This will apply the specified impulse to the game object at the specified point. If point != position, applyImpulse will also change the object’s angular momentum. Otherwise, only linear momentum will change.
Parameters: | point (the point to apply the impulse to (in world coordinates)) – the point to apply the impulse to (in world coordinates) |
---|
Suspends physics for this object.
Resumes physics for this object.
Note
The objects linear velocity will be applied from when the dynamics were suspended.
Enables rigid body physics for this object.
Rigid body physics allows the object to roll on collisions.
Disables rigid body physics for this object.
Sets this object’s parent. Control the shape status with the optional compound and ghost parameters:
In that case you can control if it should be ghost or not:
Parameters: |
|
---|
Note
If the object type is sensor, it stays ghost regardless of ghost parameter
Removes this objects parent.
Returns the user data object associated with this game object’s physics controller.
Gets a list of all property names.
Returns: | All property names for this object. |
---|---|
Return type: | list |
Parameters: | other (KX_GameObject or list [x, y, z]) – a point or another KX_GameObject to measure the distance to. |
---|---|
Returns: | distance to another object or point. |
Return type: | float |
Returns the vector and the distance to another object or point. The vector is normalized unless the distance is 0, in which a zero length vector is returned.
Parameters: | other (KX_GameObject or list [x, y, z]) – a point or another KX_GameObject to get the vector and distance to. |
---|---|
Returns: | (distance, globalVector(3), localVector(3)) |
Return type: | 3-tuple (float, 3-tuple (x, y, z), 3-tuple (x, y, z)) |
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: |
|
---|---|
Returns: | the first object hit or None if no object or object does not match prop |
Return type: |
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. if poly is 2, returns a 5-tuple with in addition a 2D vector with the UV mapping of the hit point as 5th element.
# shoot along the axis gun-gunAim (gunAim should be collision-free)
obj, point, normal = gun.rayCast(gunAim, None, 50)
if obj:
# do something
pass
The face paremeter determines the orientation of the normal.
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.
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: |
|
---|---|
Returns: | (object, hitpoint, hitnormal) or (object, hitpoint, hitnormal, polygon) or (object, hitpoint, hitnormal, polygon, hituv).
|
Return type: |
|
Note
The ray ignores the object on which the method is called. It is casted from/to object center or explicit [x, y, z] points.
Set the objects collision margin.
Parameters: | margin (float) – the collision margin distance in blender units. |
---|
Note
If this object has no physics controller (a physics ID of zero), this function will raise RuntimeError.
Sends a message.
Parameters: |
|
---|
Updates the physics system with the changed mesh.
If no arguments are given the physics mesh will be re-created from the first mesh assigned to the game object.
Parameters: |
|
---|---|
Returns: | True if reinstance succeeded, False if it failed. |
Return type: | boolean |
Note
If this object has instances the other instances will be updated too.
Note
The gameObject argument has an advantage that it can convert from a mesh with modifiers applied (such as subsurf).
Warning
Only triangle mesh type objects are supported currently (not convex hull)
Warning
If the object is a part of a combound object it will fail (parent or child)
Warning
Rebuilding the physics mesh can be slow, running many times per second will give a performance hit.
Return the value matching key, or the default value if its not found. :return: The key value or a default.
Plays an action.
Parameters: |
|
---|
Stop playing the action on the given layer.
Parameters: | layer (integer) – The layer to stop playing. |
---|
Gets the current frame of the action playing in the supplied layer.
Parameters: | layer (integer) – The layer that you want to get the frame from. |
---|---|
Returns: | The current frame of the action |
Return type: | float |
Set the current frame of the action playing in the supplied layer.
Parameters: |
|
---|
Checks to see if there is an action playing in the given layer.
Parameters: | layer (integer) – The layer to check for a playing action. |
---|---|
Returns: | Whether or not the action is playing |
Return type: | boolean |