11 This module contains the classes that appear as instances in the Game Engine. A
12 script must interact with these classes if it is to affect the behaviour of
15 The following example would move an object (i.e. an instance of
16 :class:`KX_GameObject`) one unit up.
18 .. code-block:: python
20 # bge.types.SCA_PythonController
21 cont = bge.logic.getCurrentController()
23 # bge.types.KX_GameObject
25 obj.worldPosition.z += 1
27 To run the code, it could be placed in a Blender text block and executed with
28 a :class:`SCA_PythonController` logic brick.
34 .. class:: PyObjectPlus
36 PyObjectPlus base class of most other types in the Game Engine.
38 .. attribute:: invalid
40 Test if the object has been freed by the game engine and is no longer valid.
42 Normally this is not a problem but when storing game engine data in the GameLogic module,
43 KX_Scenes or other KX_GameObjects its possible to hold a reference to invalid data.
44 Calling an attribute or method on an invalid object will raise a SystemError.
46 The invalid attribute allows testing for this case without exception handling.
50 .. class:: CValue(PyObjectPlus)
52 This class is a basis for other classes.
56 The name of this CValue derived object (read-only).
60 .. class:: CPropValue(CValue)
62 This class has no python functions
64 .. class:: SCA_ILogicBrick(CValue)
66 Base class for all logic bricks.
68 .. attribute:: executePriority
70 This determines the order controllers are evaluated, and actuators are activated (lower priority is executed first).
72 :type: executePriority: int
76 The game object this logic brick is attached to (read-only).
78 :type: :class:`KX_GameObject` or None in exceptional cases.
82 The name of this logic brick (read-only).
86 .. class:: SCA_PythonKeyboard(PyObjectPlus)
92 A dictionary containing the status of each keyboard event or key. (read-only).
94 :type: dictionary {:ref:`keycode<keyboard-keys>`::ref:`status<input-status>`, ...}
96 .. attribute:: active_events
98 A dictionary containing the status of only the active keyboard events or keys. (read-only).
100 :type: dictionary {:ref:`keycode<keyboard-keys>`::ref:`status<input-status>`, ...}
103 .. function:: getClipboard()
105 Gets the clipboard text.
109 .. function:: setClipboard(text)
111 Sets the clipboard text.
113 :arg text: New clipboard text
116 .. class:: SCA_PythonMouse(PyObjectPlus)
120 .. attribute:: events
122 a dictionary containing the status of each mouse event. (read-only).
124 :type: dictionary {:ref:`keycode<mouse-keys>`::ref:`status<input-status>`, ...}
126 .. attribute:: active_events
128 a dictionary containing the status of only the active mouse events. (read-only).
130 :type: dictionary {:ref:`keycode<mouse-keys>`::ref:`status<input-status>`, ...}
132 .. attribute:: position
134 The normalized x and y position of the mouse cursor.
138 .. attribute:: visible
140 The visibility of the mouse cursor.
144 .. class:: SCA_IObject(CValue)
146 This class has no python functions
148 .. class:: SCA_ISensor(SCA_ILogicBrick)
150 Base class for all sensor logic bricks.
152 .. attribute:: usePosPulseMode
154 Flag to turn positive pulse mode on and off.
158 .. attribute:: useNegPulseMode
160 Flag to turn negative pulse mode on and off.
164 .. attribute:: frequency
166 The frequency for pulse mode sensors.
172 level Option whether to detect level or edge transition when entering a state.
173 It makes a difference only in case of logic state transition (state actuator).
174 A level detector will immediately generate a pulse, negative or positive
175 depending on the sensor condition, as soon as the state is activated.
176 A edge detector will wait for a state change before generating a pulse.
177 note: mutually exclusive with :data:`tap`, enabling will disable :data:`tap`.
183 When enabled only sensors that are just activated will send a positive event,
184 after this they will be detected as negative by the controllers.
185 This will make a key thats held act as if its only tapped for an instant.
186 note: mutually exclusive with :data:`level`, enabling will disable :data:`level`.
190 .. attribute:: invert
192 Flag to set if this sensor activates on positive or negative events.
196 .. attribute:: triggered
198 True if this sensor brick is in a positive state. (read-only).
202 .. attribute:: positive
204 True if this sensor brick is in a positive state. (read-only).
208 .. attribute:: pos_ticks
210 The number of ticks since the last positive pulse (read-only).
214 .. attribute:: neg_ticks
216 The number of ticks since the last negative pulse (read-only).
220 .. attribute:: status
222 The status of the sensor (read-only): can be one of :ref:`these constants<sensor-status>`.
228 This convenient attribute combines the values of triggered and positive attributes.
232 Reset sensor internal state, effect depends on the type of sensor and settings.
234 The sensor is put in its initial state as if it was just activated.
236 .. class:: SCA_IController(SCA_ILogicBrick)
238 Base class for all controller logic bricks.
242 The controllers state bitmask. This can be used with the GameObject's state to test if the controller is active.
246 .. attribute:: sensors
248 A list of sensors linked to this controller.
250 :type: sequence supporting index/string lookups and iteration.
254 The sensors are not necessarily owned by the same object.
258 When objects are instanced in dupligroups links may be lost from objects outside the dupligroup.
260 .. attribute:: actuators
262 A list of actuators linked to this controller.
264 :type: sequence supporting index/string lookups and iteration.
268 The sensors are not necessarily owned by the same object.
272 When objects are instanced in dupligroups links may be lost from objects outside the dupligroup.
274 .. attribute:: useHighPriority
276 When set the controller executes always before all other controllers that dont have this set.
282 Order of execution between high priority controllers is not guaranteed.
284 .. class:: SCA_IActuator(SCA_ILogicBrick)
286 Base class for all actuator logic bricks.
288 .. class:: BL_ActionActuator(SCA_IActuator)
290 Action Actuators apply an action to an actor.
292 .. attribute:: action
294 The name of the action to set as the current action.
298 .. attribute:: frameStart
300 Specifies the starting frame of the animation.
304 .. attribute:: frameEnd
306 Specifies the ending frame of the animation.
310 .. attribute:: blendIn
312 Specifies the number of frames of animation to generate when making transitions between actions.
316 .. attribute:: priority
318 Sets the priority of this actuator. Actuators will lower priority numbers will override actuators with higher numbers.
324 Sets the current frame for the animation.
328 .. attribute:: propName
330 Sets the property to be used in FromProp playback mode.
334 .. attribute:: blendTime
336 Sets the internal frame timer. This property must be in the range from 0.0 to blendIn.
342 The operation mode of the actuator. Can be one of :ref:`these constants<action-actuator>`.
346 .. attribute:: useContinue
348 The actions continue option, True or False. When True, the action will always play from where last left off,
349 otherwise negative events to this actuator will reset it to its start frame.
353 .. attribute:: framePropName
355 The name of the property that is set to the current frame number.
359 .. class:: BL_Shader(PyObjectPlus)
361 BL_Shader GLSL shaders.
365 .. method:: setUniformfv(name, fList)
367 Set a uniform with a list of float values
369 :arg name: the uniform name
371 :arg fList: a list (2, 3 or 4 elements) of float values
372 :type fList: list[float]
374 .. method:: delSource()
376 Clear the shader. Use this method before the source is changed with :data:`setSource`.
378 .. method:: getFragmentProg()
380 Returns the fragment program.
382 :return: The fragment program.
385 .. method:: getVertexProg()
387 Get the vertex program.
389 :return: The vertex program.
392 .. method:: isValid()
394 Check if the shader is valid.
396 :return: True if the shader is valid
399 .. method:: setAttrib(enum)
401 Set attribute location. (The parameter is ignored a.t.m. and the value of "tangent" is always used.)
403 :arg enum: attribute location value
406 .. method:: setNumberOfPasses( max_pass )
408 Set the maximum number of passes. Not used a.t.m.
410 :arg max_pass: the maximum number of passes
411 :type max_pass: integer
413 .. method:: setSampler(name, index)
415 Set uniform texture sample index.
417 :arg name: Uniform name
419 :arg index: Texture sample index.
422 .. method:: setSource(vertexProgram, fragmentProgram)
424 Set the vertex and fragment programs
426 :arg vertexProgram: Vertex program
427 :type vertexProgram: string
428 :arg fragmentProgram: Fragment program
429 :type fragmentProgram: string
431 .. method:: setUniform1f(name, fx)
433 Set a uniform with 1 float value.
435 :arg name: the uniform name
437 :arg fx: Uniform value
440 .. method:: setUniform1i(name, ix)
442 Set a uniform with an integer value.
444 :arg name: the uniform name
446 :arg ix: the uniform value
449 .. method:: setUniform2f(name, fx, fy)
451 Set a uniform with 2 float values
453 :arg name: the uniform name
455 :arg fx: first float value
458 :arg fy: second float value
461 .. method:: setUniform2i(name, ix, iy)
463 Set a uniform with 2 integer values
465 :arg name: the uniform name
467 :arg ix: first integer value
469 :arg iy: second integer value
472 .. method:: setUniform3f(name, fx, fy, fz)
474 Set a uniform with 3 float values.
476 :arg name: the uniform name
478 :arg fx: first float value
480 :arg fy: second float value
482 :arg fz: third float value
485 .. method:: setUniform3i(name, ix, iy, iz)
487 Set a uniform with 3 integer values
489 :arg name: the uniform name
491 :arg ix: first integer value
493 :arg iy: second integer value
495 :arg iz: third integer value
498 .. method:: setUniform4f(name, fx, fy, fz, fw)
500 Set a uniform with 4 float values.
502 :arg name: the uniform name
504 :arg fx: first float value
506 :arg fy: second float value
508 :arg fz: third float value
510 :arg fw: fourth float value
513 .. method:: setUniform4i(name, ix, iy, iz, iw)
515 Set a uniform with 4 integer values
517 :arg name: the uniform name
519 :arg ix: first integer value
521 :arg iy: second integer value
523 :arg iz: third integer value
525 :arg iw: fourth integer value
528 .. method:: setUniformDef(name, type)
532 :arg name: the uniform name
534 :arg type: uniform type
535 :type type: UNI_NONE, UNI_INT, UNI_FLOAT, UNI_INT2, UNI_FLOAT2, UNI_INT3, UNI_FLOAT3, UNI_INT4, UNI_FLOAT4, UNI_MAT3, UNI_MAT4, UNI_MAX
537 .. method:: setUniformMatrix3(name, mat, transpose)
539 Set a uniform with a 3x3 matrix value
541 :arg name: the uniform name
543 :arg mat: A 3x3 matrix [[f, f, f], [f, f, f], [f, f, f]]
544 :type mat: 3x3 matrix
545 :arg transpose: set to True to transpose the matrix
546 :type transpose: boolean
548 .. method:: setUniformMatrix4(name, mat, transpose)
550 Set a uniform with a 4x4 matrix value
552 :arg name: the uniform name
554 :arg mat: A 4x4 matrix [[f, f, f, f], [f, f, f, f], [f, f, f, f], [f, f, f, f]]
555 :type mat: 4x4 matrix
556 :arg transpose: set to True to transpose the matrix
557 :type transpose: boolean
559 .. method:: setUniformiv(name, iList)
561 Set a uniform with a list of integer values
563 :arg name: the uniform name
565 :arg iList: a list (2, 3 or 4 elements) of integer values
566 :type iList: list[integer]
568 .. method:: validate()
570 Validate the shader object.
572 .. class:: BL_ShapeActionActuator(SCA_IActuator)
574 ShapeAction Actuators apply an shape action to an mesh object.
576 .. attribute:: action
578 The name of the action to set as the current shape action.
582 .. attribute:: frameStart
584 Specifies the starting frame of the shape animation.
588 .. attribute:: frameEnd
590 Specifies the ending frame of the shape animation.
594 .. attribute:: blendIn
596 Specifies the number of frames of animation to generate when making transitions between actions.
600 .. attribute:: priority
602 Sets the priority of this actuator. Actuators will lower priority numbers will override actuators with higher numbers.
608 Sets the current frame for the animation.
612 .. attribute:: propName
614 Sets the property to be used in FromProp playback mode.
618 .. attribute:: blendTime
620 Sets the internal frame timer. This property must be in the range from 0.0 to blendin.
626 The operation mode of the actuator. Can be one of :ref:`these constants<shape-action-actuator>`.
630 .. attribute:: framePropName
632 The name of the property that is set to the current frame number.
637 .. class:: KX_SteeringActuator(SCA_IActuator)
639 Steering Actuator for navigation.
641 .. attribute:: behavior
643 The steering behavior to use.
645 :type: one of :ref:`these constants <logic-steering-actuator>`
647 .. attribute:: velocity
653 .. attribute:: acceleration
659 .. attribute:: turnspeed
665 .. attribute:: distance
671 .. attribute:: target
675 :type: :class:`KX_GameObject`
677 .. attribute:: navmesh
681 :type: :class:`KX_GameObject`
683 .. attribute:: selfterminated
685 Terminate when target is reached
689 .. attribute:: enableVisualization
691 Enable debug visualization
695 .. attribute:: pathUpdatePeriod
701 .. class:: CListValue(CPropValue)
703 This is a list like object used in the game engine internally that behaves similar to a python list in most ways.
705 As well as the normal index lookup (``val= clist[i]``), CListValue supports string lookups (``val= scene.objects["Cube"]``)
707 Other operations such as ``len(clist)``, ``list(clist)``, ``clist[0:10]`` are also supported.
709 .. method:: append(val)
711 Add an item to the list (like pythons append)
715 Appending values to the list can cause crashes when the list is used internally by the game engine.
717 .. method:: count(val)
719 Count the number of instances of a value in the list.
721 :return: number of instances
724 .. method:: index(val)
726 Return the index of a value in the list.
728 :return: The index of the value in the list.
731 .. method:: reverse()
733 Reverse the order of the list.
735 .. method:: get(key, default=None)
737 Return the value matching key, or the default value if its not found.
739 :return: The key value or a default.
741 .. method:: from_id(id)
743 This is a funtion especially for the game engine to return a value with a spesific id.
745 Since object names are not always unique, the id of an object can be used to get an object from the CValueList.
749 .. code-block:: python
751 myObID=id(gameObject)
752 ob= scene.objects.from_id(myObID)
754 Where ``myObID`` is an int or long from the id function.
756 This has the advantage that you can store the id in places you could not store a gameObject.
760 The id is derived from a memory location and will be different each time the game engine starts.
762 .. class:: KX_BlenderMaterial(PyObjectPlus)
766 .. attribute:: shader
768 The materials shader.
770 :type: :class:`BL_Shader`
772 .. attribute:: blending
774 Ints used for pixel blending, (src, dst), matching the setBlending method.
776 :type: (integer, integer)
778 .. attribute:: material_index
780 The material's index.
784 .. method:: getShader()
786 Returns the material's shader.
788 :return: the material's shader
789 :rtype: :class:`BL_Shader`
791 .. method:: setBlending(src, dest)
793 Set the pixel color arithmetic functions.
795 :arg src: Specifies how the red, green, blue, and alpha source blending factors are computed.
796 :type src: Value in...
801 * GL_ONE_MINUS_SRC_COLOR,
803 * GL_ONE_MINUS_DST_COLOR,
805 * GL_ONE_MINUS_SRC_ALPHA,
807 * GL_ONE_MINUS_DST_ALPHA,
808 * GL_SRC_ALPHA_SATURATE
810 :arg dest: Specifies how the red, green, blue, and alpha destination blending factors are computed.
811 :type dest: Value in...
816 * GL_ONE_MINUS_SRC_COLOR
818 * GL_ONE_MINUS_DST_COLOR
820 * GL_ONE_MINUS_SRC_ALPHA
822 * GL_ONE_MINUS_DST_ALPHA
823 * GL_SRC_ALPHA_SATURATE
825 .. method:: getMaterialIndex()
827 Returns the material's index.
829 :return: the material's index
832 .. class:: KX_CameraActuator(SCA_IActuator)
834 Applies changes to a camera.
836 .. attribute:: damping
838 strength of of the camera following movement.
844 The camera axis (0, 1, 2) for positive ``XYZ``, (3, 4, 5) for negative ``XYZ``.
850 minimum distance to the target object maintained by the actuator.
856 maximum distance to stay from the target object.
860 .. attribute:: height
862 height to stay above the target object.
866 .. attribute:: object
868 the object this actuator tracks.
870 :type: :class:`KX_GameObject` or None
872 .. class:: KX_ConstraintActuator(SCA_IActuator)
874 A constraint actuator limits the position, rotation, distance or orientation of an object.
878 Time constant of the constraint expressed in frame (not use by Force field constraint).
882 .. attribute:: rotDamp
884 Time constant for the rotation expressed in frame (only for the distance constraint), 0 = use damp for rotation as well.
888 .. attribute:: direction
890 The reference direction in world coordinate for the orientation constraint.
892 :type: 3-tuple of float: (x, y, z)
894 .. attribute:: option
896 Binary combination of :ref:`these constants <constraint-actuator-option>`
902 activation time of the actuator. The actuator disables itself after this many frame. If set to 0, the actuator is not limited in time.
906 .. attribute:: propName
908 the name of the property or material for the ray detection of the distance constraint.
914 The lower bound of the constraint. For the rotation and orientation constraint, it represents radiant.
918 .. attribute:: distance
920 the target distance of the distance constraint.
926 the upper bound of the constraint. For rotation and orientation constraints, it represents radiant.
930 .. attribute:: rayLength
932 the length of the ray of the distance constraint.
938 type of constraint. Use one of the :ref:`these constants <constraint-actuator-limit>`
943 .. class:: KX_ConstraintWrapper(PyObjectPlus)
947 .. method:: getConstraintId(val)
949 Returns the contraint's ID
951 :return: the constraint's ID
954 .. class:: KX_GameActuator(SCA_IActuator)
956 The game actuator loads a new .blend file, restarts the current .blend file or quits the game.
958 .. attribute:: fileName
960 the new .blend file to load.
966 The mode of this actuator. Can be on of :ref:`these constants <game-actuator>`
970 .. class:: KX_GameObject(SCA_IObject)
972 All game objects are derived from this class.
974 Properties assigned to game objects are accessible as attributes of this class.
978 Calling ANY method or attribute on an object that has been removed from a scene will raise a SystemError,
979 if an object may have been removed since last accessing it use the :data:`invalid` attribute to check.
981 KX_GameObject can be subclassed to extend functionality. For example:
983 .. code-block:: python
987 class CustomGameObject(bge.types.KX_GameObject):
990 def __init__(self, old_owner):
991 # "old_owner" can just be ignored. At this point, "self" is
992 # already the object in the scene, and "old_owner" has been
995 # New attributes can be defined - but we could also use a game
996 # property, like "self['rate']".
997 self.rate = CustomGameObject.RATE
1000 self.worldPosition.z += self.rate
1003 if self.worldPosition.z > 1.0:
1004 self.rate = -CustomGameObject.RATE
1005 elif self.worldPosition.z < 0.0:
1006 self.rate = CustomGameObject.RATE
1010 old_object = cont.owner
1011 mutated_object = CustomGameObject(cont.owner)
1013 # After calling the constructor above, references to the old object
1014 # should not be used.
1015 assert(old_object is not mutated_object)
1016 assert(old_object.invalid)
1017 assert(mutated_object is cont.owner)
1019 # Called later - note we are now working with the mutated object.
1023 When subclassing objects other than empties and meshes, the specific type
1024 should be used - e.g. inherit from :class:`BL_ArmatureObject` when the object
1025 to mutate is an armature.
1029 The object's name. (read-only).
1041 The object must have a physics controller for the mass to be applied, otherwise the mass value will be returned as 0.0.
1043 .. attribute:: linVelocityMin
1045 Enforces the object keeps moving at a minimum velocity.
1051 Applies to dynamic and rigid body objects only.
1055 A value of 0.0 disables this option.
1059 While objects are stationary the minimum velocity will not be applied.
1061 .. attribute:: linVelocityMax
1063 Clamp the maximum linear velocity to prevent objects moving beyond a set speed.
1069 Applies to dynamic and rigid body objects only.
1073 A value of 0.0 disables this option (rather then setting it stationary).
1075 .. attribute:: localInertia
1077 the object's inertia vector in local coordinates. Read only.
1079 :type: list [ix, iy, iz]
1081 .. attribute:: parent
1083 The object's parent object. (read-only).
1085 :type: :class:`KX_GameObject` or None
1087 .. attribute:: groupMembers
1089 Returns the list of group members if the object is a group object, otherwise None is returned.
1091 :type: :class:`CListValue` of :class:`KX_GameObject` or None
1093 .. attribute:: groupObject
1095 Returns the group object that the object belongs to or None if the object is not part of a group.
1097 :type: :class:`KX_GameObject` or None
1099 .. attribute:: scene
1101 The object's scene. (read-only).
1103 :type: :class:`KX_Scene` or None
1105 .. attribute:: visible
1113 Game logic will still run for invisible objects.
1115 .. attribute:: color
1117 The object color of the object. [r, g, b, a]
1119 :type: :class:`mathutils.Vector`
1121 .. attribute:: occlusion
1123 occlusion capability flag.
1127 .. attribute:: position
1129 The object's position. [x, y, z] On write: local position, on read: world position
1131 .. deprecated:: use :data:`localPosition` and :data:`worldPosition`.
1133 :type: :class:`mathutils.Vector`
1135 .. attribute:: orientation
1137 The object's orientation. 3x3 Matrix. You can also write a Quaternion or Euler vector. On write: local orientation, on read: world orientation
1139 .. deprecated:: use :data:`localOrientation` and :data:`worldOrientation`.
1141 :type: :class:`mathutils.Matrix`
1143 .. attribute:: scaling
1145 The object's scaling factor. [sx, sy, sz] On write: local scaling, on read: world scaling
1147 .. deprecated:: use :data:`localScale` and :data:`worldScale`.
1149 :type: :class:`mathutils.Vector`
1151 .. attribute:: localOrientation
1153 The object's local orientation. 3x3 Matrix. You can also write a Quaternion or Euler vector.
1155 :type: :class:`mathutils.Matrix`
1157 .. attribute:: worldOrientation
1159 The object's world orientation. 3x3 Matrix.
1161 :type: :class:`mathutils.Matrix`
1163 .. attribute:: localScale
1165 The object's local scaling factor. [sx, sy, sz]
1167 :type: :class:`mathutils.Vector`
1169 .. attribute:: worldScale
1171 The object's world scaling factor. [sx, sy, sz]
1173 :type: :class:`mathutils.Vector`
1175 .. attribute:: localPosition
1177 The object's local position. [x, y, z]
1179 :type: :class:`mathutils.Vector`
1181 .. attribute:: worldPosition
1183 The object's world position. [x, y, z]
1185 :type: :class:`mathutils.Vector`
1187 .. attribute:: localTransform
1189 The object's local space transform matrix. 4x4 Matrix.
1191 :type: :class:`mathutils.Matrix`
1193 .. attribute:: worldTransform
1195 The object's world space transform matrix. 4x4 Matrix.
1197 :type: :class:`mathutils.Matrix`
1199 .. attribute:: localLinearVelocity
1201 The object's local linear velocity. [x, y, z]
1203 :type: :class:`mathutils.Vector`
1205 .. attribute:: worldLinearVelocity
1207 The object's world linear velocity. [x, y, z]
1209 :type: :class:`mathutils.Vector`
1211 .. attribute:: localAngularVelocity
1213 The object's local angular velocity. [x, y, z]
1215 :type: :class:`mathutils.Vector`
1217 .. attribute:: worldAngularVelocity
1219 The object's world angular velocity. [x, y, z]
1221 :type: :class:`mathutils.Vector`
1223 .. attribute:: timeOffset
1225 adjust the slowparent delay at runtime.
1229 .. attribute:: state
1231 the game object's state bitmask, using the first 30 bits, one bit must always be set.
1235 .. attribute:: meshes
1237 a list meshes for this object.
1239 :type: list of :class:`KX_MeshProxy`
1243 Most objects use only 1 mesh.
1247 Changes to this list will not update the KX_GameObject.
1249 .. attribute:: sensors
1251 a sequence of :class:`SCA_ISensor` objects with string/index lookups and iterator support.
1257 This attribute is experemental and may be removed (but probably wont be).
1261 Changes to this list will not update the KX_GameObject.
1263 .. attribute:: controllers
1265 a sequence of :class:`SCA_IController` objects with string/index lookups and iterator support.
1267 :type: list of :class:`SCA_ISensor`
1271 This attribute is experemental and may be removed (but probably wont be).
1275 Changes to this list will not update the KX_GameObject.
1277 .. attribute:: actuators
1279 a list of :class:`SCA_IActuator` with string/index lookups and iterator support.
1285 This attribute is experemental and may be removed (but probably wont be).
1289 Changes to this list will not update the KX_GameObject.
1291 .. attribute:: attrDict
1293 get the objects internal python attribute dictionary for direct (faster) access.
1297 .. attribute:: children
1299 direct children of this object, (read-only).
1301 :type: :class:`CListValue` of :class:`KX_GameObject`'s
1303 .. attribute:: childrenRecursive
1305 all children of this object including childrens children, (read-only).
1307 :type: :class:`CListValue` of :class:`KX_GameObject`'s
1311 The number of seconds until the object ends, assumes 50fps.
1312 (when added with an add object actuator), (read-only).
1316 .. method:: endObject()
1318 Delete this object, can be used in place of the EndObject Actuator.
1320 The actual removal of the object from the scene is delayed.
1322 .. method:: replaceMesh(mesh, useDisplayMesh=True, usePhysicsMesh=False)
1324 Replace the mesh of this object with a new mesh. This works the same was as the actuator.
1326 :arg mesh: mesh to replace or the meshes name.
1327 :type mesh: :class:`MeshProxy` or string
1328 :arg useDisplayMesh: when enabled the display mesh will be replaced (optional argument).
1329 :type useDisplayMesh: boolean
1330 :arg usePhysicsMesh: when enabled the physics mesh will be replaced (optional argument).
1331 :type usePhysicsMesh: boolean
1333 .. method:: setVisible(visible, recursive)
1335 Sets the game object's visible flag.
1337 :arg visible: the visible state to set.
1338 :type visible: boolean
1339 :arg recursive: optional argument to set all childrens visibility flag too.
1340 :type recursive: boolean
1342 .. method:: setOcclusion(occlusion, recursive)
1344 Sets the game object's occlusion capability.
1346 :arg occlusion: the state to set the occlusion to.
1347 :type occlusion: boolean
1348 :arg recursive: optional argument to set all childrens occlusion flag too.
1349 :type recursive: boolean
1351 .. method:: alignAxisToVect(vect, axis=2, factor=1.0)
1353 Aligns any of the game object's axis along the given vector.
1356 :arg vect: a vector to align the axis.
1357 :type vect: 3D vector
1358 :arg axis: The axis you want to align
1365 :arg factor: Only rotate a feaction of the distance to the target vector (0.0 - 1.0)
1368 .. method:: getAxisVect(vect)
1370 Returns the axis vector rotates by the objects worldspace orientation.
1371 This is the equivalent of multiplying the vector by the orientation matrix.
1373 :arg vect: a vector to align the axis.
1374 :type vect: 3D Vector
1375 :return: The vector in relation to the objects rotation.
1378 .. method:: applyMovement(movement, local=False)
1380 Sets the game object's movement.
1382 :arg movement: movement vector.
1383 :type movement: 3D Vector
1385 * False: you get the "global" movement ie: relative to world orientation.
1386 * True: you get the "local" movement ie: relative to object orientation.
1389 .. method:: applyRotation(rotation, local=False)
1391 Sets the game object's rotation.
1393 :arg rotation: rotation vector.
1394 :type rotation: 3D Vector
1396 * False: you get the "global" rotation ie: relative to world orientation.
1397 * True: you get the "local" rotation ie: relative to object orientation.
1400 .. method:: applyForce(force, local=False)
1402 Sets the game object's force.
1404 This requires a dynamic object.
1406 :arg force: force vector.
1407 :type force: 3D Vector
1409 * False: you get the "global" force ie: relative to world orientation.
1410 * True: you get the "local" force ie: relative to object orientation.
1411 :type local: boolean
1413 .. method:: applyTorque(torque, local=False)
1415 Sets the game object's torque.
1417 This requires a dynamic object.
1419 :arg torque: torque vector.
1420 :type torque: 3D Vector
1422 * False: you get the "global" torque ie: relative to world orientation.
1423 * True: you get the "local" torque ie: relative to object orientation.
1424 :type local: boolean
1426 .. method:: getLinearVelocity(local=False)
1428 Gets the game object's linear velocity.
1430 This method returns the game object's velocity through it's centre of mass, ie no angular velocity component.
1433 * False: you get the "global" velocity ie: relative to world orientation.
1434 * True: you get the "local" velocity ie: relative to object orientation.
1435 :type local: boolean
1436 :return: the object's linear velocity.
1437 :rtype: list [vx, vy, vz]
1439 .. method:: setLinearVelocity(velocity, local=False)
1441 Sets the game object's linear velocity.
1443 This method sets game object's velocity through it's centre of mass,
1444 ie no angular velocity component.
1446 This requires a dynamic object.
1448 :arg velocity: linear velocity vector.
1449 :type velocity: 3D Vector
1451 * False: you get the "global" velocity ie: relative to world orientation.
1452 * True: you get the "local" velocity ie: relative to object orientation.
1453 :type local: boolean
1455 .. method:: getAngularVelocity(local=False)
1457 Gets the game object's angular velocity.
1460 * False: you get the "global" velocity ie: relative to world orientation.
1461 * True: you get the "local" velocity ie: relative to object orientation.
1462 :type local: boolean
1463 :return: the object's angular velocity.
1464 :rtype: list [vx, vy, vz]
1466 .. method:: setAngularVelocity(velocity, local=False)
1468 Sets the game object's angular velocity.
1470 This requires a dynamic object.
1472 :arg velocity: angular velocity vector.
1473 :type velocity: boolean
1475 * False: you get the "global" velocity ie: relative to world orientation.
1476 * True: you get the "local" velocity ie: relative to object orientation.
1478 .. method:: getVelocity(point=(0, 0, 0))
1480 Gets the game object's velocity at the specified point.
1482 Gets the game object's velocity at the specified point, including angular
1485 :arg point: optional point to return the velocity for, in local coordinates.
1486 :type point: 3D Vector
1487 :return: the velocity at the specified point.
1488 :rtype: list [vx, vy, vz]
1490 .. method:: getReactionForce()
1492 Gets the game object's reaction force.
1494 The reaction force is the force applied to this object over the last simulation timestep.
1495 This also includes impulses, eg from collisions.
1497 :return: the reaction force of this object.
1498 :rtype: list [fx, fy, fz]
1502 This is not implimented at the moment.
1504 .. method:: applyImpulse(point, impulse)
1506 Applies an impulse to the game object.
1508 This will apply the specified impulse to the game object at the specified point.
1509 If point != position, applyImpulse will also change the object's angular momentum.
1510 Otherwise, only linear momentum will change.
1512 :arg point: the point to apply the impulse to (in world coordinates)
1513 :type point: the point to apply the impulse to (in world coordinates)
1515 .. method:: suspendDynamics()
1517 Suspends physics for this object.
1519 .. method:: restoreDynamics()
1521 Resumes physics for this object.
1525 The objects linear velocity will be applied from when the dynamics were suspended.
1527 .. method:: enableRigidBody()
1529 Enables rigid body physics for this object.
1531 Rigid body physics allows the object to roll on collisions.
1533 .. method:: disableRigidBody()
1535 Disables rigid body physics for this object.
1537 .. method:: setParent(parent, compound=True, ghost=True)
1539 Sets this object's parent.
1540 Control the shape status with the optional compound and ghost parameters:
1542 In that case you can control if it should be ghost or not:
1544 :arg parent: new parent object.
1545 :type parent: :class:`KX_GameObject`
1546 :arg compound: whether the shape should be added to the parent compound shape.
1548 * True: the object shape should be added to the parent compound shape.
1549 * False: the object should keep its individual shape.
1551 :type compound: boolean
1552 :arg ghost: whether the object should be ghost while parented.
1554 * True: if the object should be made ghost while parented.
1555 * False: if the object should be solid while parented.
1557 :type ghost: boolean
1561 If the object type is sensor, it stays ghost regardless of ghost parameter
1563 .. method:: removeParent()
1565 Removes this objects parent.
1567 .. method:: getPhysicsId()
1569 Returns the user data object associated with this game object's physics controller.
1571 .. method:: getPropertyNames()
1573 Gets a list of all property names.
1575 :return: All property names for this object.
1578 .. method:: getDistanceTo(other)
1580 :arg other: a point or another :class:`KX_GameObject` to measure the distance to.
1581 :type other: :class:`KX_GameObject` or list [x, y, z]
1582 :return: distance to another object or point.
1585 .. method:: getVectTo(other)
1587 Returns the vector and the distance to another object or point.
1588 The vector is normalized unless the distance is 0, in which a zero length vector is returned.
1590 :arg other: a point or another :class:`KX_GameObject` to get the vector and distance to.
1591 :type other: :class:`KX_GameObject` or list [x, y, z]
1592 :return: (distance, globalVector(3), localVector(3))
1593 :rtype: 3-tuple (float, 3-tuple (x, y, z), 3-tuple (x, y, z))
1595 .. method:: rayCastTo(other, dist, prop)
1597 Look towards another point/object and find first object hit within dist that matches prop.
1599 The ray is always casted from the center of the object, ignoring the object itself.
1600 The ray is casted towards the center of another object or an explicit [x, y, z] point.
1601 Use rayCast() if you need to retrieve the hit point
1603 :arg other: [x, y, z] or object towards which the ray is casted
1604 :type other: :class:`KX_GameObject` or 3-tuple
1605 :arg dist: max distance to look (can be negative => look behind); 0 or omitted => detect up to other
1607 :arg prop: property name that object must have; can be omitted => detect any object
1609 :return: the first object hit or None if no object or object does not match prop
1610 :rtype: :class:`KX_GameObject`
1612 .. method:: rayCast(objto, objfrom, dist, prop, face, xray, poly)
1614 Look from a point/object to another point/object and find first object hit within dist that matches prop.
1615 if poly is 0, returns a 3-tuple with object reference, hit point and hit normal or (None, None, None) if no hit.
1616 if poly is 1, returns a 4-tuple with in addition a :class:`KX_PolyProxy` as 4th element.
1617 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.
1619 .. code-block:: python
1621 # shoot along the axis gun-gunAim (gunAim should be collision-free)
1622 obj, point, normal = gun.rayCast(gunAim, None, 50)
1627 The face paremeter determines the orientation of the normal.
1629 * 0 => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1630 * 1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
1632 The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
1633 The prop and xray parameters interact as follow.
1635 * prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
1636 * prop off, xray on : idem.
1637 * prop on, xray off: return closest hit if it matches prop, no hit otherwise.
1638 * 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.
1640 The :class:`KX_PolyProxy` 4th element of the return tuple when poly=1 allows to retrieve information on the polygon hit by the ray.
1641 If there is no hit or the hit object is not a static mesh, None is returned as 4th element.
1643 The ray ignores collision-free objects and faces that dont have the collision flag enabled, you can however use ghost objects.
1645 :arg objto: [x, y, z] or object to which the ray is casted
1646 :type objto: :class:`KX_GameObject` or 3-tuple
1647 :arg objfrom: [x, y, z] or object from which the ray is casted; None or omitted => use self object center
1648 :type objfrom: :class:`KX_GameObject` or 3-tuple or None
1649 :arg dist: max distance to look (can be negative => look behind); 0 or omitted => detect up to to
1651 :arg prop: property name that object must have; can be omitted or "" => detect any object
1653 :arg face: normal option: 1=>return face normal; 0 or omitted => normal is oriented towards origin
1655 :arg xray: X-ray option: 1=>skip objects that don't match prop; 0 or omitted => stop on first object
1657 :arg poly: polygon option: 0, 1 or 2 to return a 3-, 4- or 5-tuple with information on the face hit.
1659 * 0 or omitted: return value is a 3-tuple (object, hitpoint, hitnormal) or (None, None, None) if no hit
1660 * 1: return value is a 4-tuple and the 4th element is a :class:`KX_PolyProxy` or None if no hit or the object doesn't use a mesh collision shape.
1661 * 2: return value is a 5-tuple and the 5th element is a 2-tuple (u, v) with the UV mapping of the hit point or None if no hit, or the object doesn't use a mesh collision shape, or doesn't have a UV mapping.
1664 :return: (object, hitpoint, hitnormal) or (object, hitpoint, hitnormal, polygon) or (object, hitpoint, hitnormal, polygon, hituv).
1666 * object, hitpoint and hitnormal are None if no hit.
1667 * polygon is valid only if the object is valid and is a static object, a dynamic object using mesh collision shape or a soft body object, otherwise it is None
1668 * hituv is valid only if polygon is valid and the object has a UV mapping, otherwise it is None
1672 * 3-tuple (:class:`KX_GameObject`, 3-tuple (x, y, z), 3-tuple (nx, ny, nz))
1673 * or 4-tuple (:class:`KX_GameObject`, 3-tuple (x, y, z), 3-tuple (nx, ny, nz), :class:`PolyProxy`)
1674 * or 5-tuple (:class:`KX_GameObject`, 3-tuple (x, y, z), 3-tuple (nx, ny, nz), :class:`PolyProxy`, 2-tuple (u, v))
1678 The ray ignores the object on which the method is called. It is casted from/to object center or explicit [x, y, z] points.
1680 .. method:: setCollisionMargin(margin)
1682 Set the objects collision margin.
1684 :arg margin: the collision margin distance in blender units.
1689 If this object has no physics controller (a physics ID of zero), this function will raise RuntimeError.
1691 .. method:: sendMessage(subject, body="", to="")
1695 :arg subject: The subject of the message
1696 :type subject: string
1697 :arg body: The body of the message (optional)
1699 :arg to: The name of the object to send the message to (optional)
1702 .. method:: reinstancePhysicsMesh(gameObject, meshObject)
1704 Updates the physics system with the changed mesh.
1706 If no arguments are given the physics mesh will be re-created from the first mesh assigned to the game object.
1708 :arg gameObject: optional argument, set the physics shape from this gameObjets mesh.
1709 :type gameObject: string, :class:`KX_GameObject` or None
1710 :arg meshObject: optional argument, set the physics shape from this mesh.
1711 :type meshObject: string, :class:`MeshProxy` or None
1713 :return: True if reinstance succeeded, False if it failed.
1718 If this object has instances the other instances will be updated too.
1722 The gameObject argument has an advantage that it can convert from a mesh with modifiers applied (such as subsurf).
1726 Only triangle mesh type objects are supported currently (not convex hull)
1730 If the object is a part of a combound object it will fail (parent or child)
1734 Rebuilding the physics mesh can be slow, running many times per second will give a performance hit.
1736 .. method:: get(key, default=None)
1738 Return the value matching key, or the default value if its not found.
1739 :return: The key value or a default.
1741 .. method:: playAction(name, start_frame, end_frame, layer=0, priority=0, blendin=0, play_mode=ACT_MODE_PLAY, layer_weight=0.0, ipo_flags=0, speed=1.0)
1745 :arg name: the name of the action
1747 :arg start: the start frame of the action
1749 :arg end: the end frame of the action
1751 :arg layer: the layer the action will play in (actions in different layers are added/blended together)
1752 :type layer: integer
1753 :arg priority: only play this action if there isn't an action currently playing in this layer with a higher (lower number) priority
1754 :type priority: integer
1755 :arg blendin: the amount of blending between this animation and the previous one on this layer
1756 :type blendin: float
1757 :arg play_mode: the play mode
1758 :type play_mode: one of :ref:`these constants <gameobject-playaction-mode>`
1759 :arg layer_weight: how much of the previous layer to use for blending (0 = add)
1760 :type layer_weight: float
1761 :arg ipo_flags: flags for the old IPO behaviors (force, etc)
1762 :type ipo_flags: int bitfield
1763 :arg speed: the playback speed of the action as a factor (1.0 = normal speed, 2.0 = 2x speed, etc)
1766 .. method:: stopAction(layer=0)
1768 Stop playing the action on the given layer.
1770 :arg layer: The layer to stop playing.
1771 :type layer: integer
1773 .. method:: getActionFrame(layer=0)
1775 Gets the current frame of the action playing in the supplied layer.
1777 :arg layer: The layer that you want to get the frame from.
1778 :type layer: integer
1780 :return: The current frame of the action
1783 .. method:: setActionFrame(frame, layer=0)
1785 Set the current frame of the action playing in the supplied layer.
1787 :arg layer: The layer where you want to set the frame
1788 :type layer: integer
1789 :arg frame: The frame to set the action to
1792 .. method:: isPlayingAction(layer=0)
1794 Checks to see if there is an action playing in the given layer.
1796 :arg layer: The layer to check for a playing action.
1797 :type layer: integer
1799 :return: Whether or not the action is playing
1802 .. class:: KX_IpoActuator(SCA_IActuator)
1804 IPO actuator activates an animation.
1806 .. attribute:: frameStart
1812 .. attribute:: frameEnd
1818 .. attribute:: propName
1820 Use this property to define the Ipo position.
1824 .. attribute:: framePropName
1826 Assign this property this action current frame number.
1832 Play mode for the ipo. Can be on of :ref:`these constants <ipo-actuator>`
1836 .. attribute:: useIpoAsForce
1838 Apply Ipo as a global or local force depending on the local option (dynamic objects only).
1842 .. attribute:: useIpoAdd
1844 Ipo is added to the current loc/rot/scale in global or local coordinate according to Local flag.
1848 .. attribute:: useIpoLocal
1850 Let the ipo acts in local coordinates, used in Force and Add mode.
1854 .. attribute:: useChildren
1856 Update IPO on all children Objects as well.
1860 .. class:: KX_LightObject(KX_GameObject)
1864 .. code-block:: python
1866 # Turn on a red alert light.
1869 co = bge.logic.getCurrentController()
1873 light.color = [1.0, 0.0, 0.0]
1877 A spot light source. See attribute :data:`type`
1881 A point light source with no attenuation. See attribute :data:`type`
1885 A point light source. See attribute :data:`type`
1889 The type of light - must be SPOT, SUN or NORMAL
1891 .. attribute:: layer
1893 The layer mask that this light affects object on.
1897 .. attribute:: energy
1899 The brightness of this light.
1903 .. attribute:: distance
1905 The maximum distance this light can illuminate. (SPOT and NORMAL lights only).
1909 .. attribute:: color
1911 The color of this light. Black = [0.0, 0.0, 0.0], White = [1.0, 1.0, 1.0].
1913 :type: list [r, g, b]
1915 .. attribute:: lin_attenuation
1917 The linear component of this light's attenuation. (SPOT and NORMAL lights only).
1921 .. attribute:: quad_attenuation
1923 The quadratic component of this light's attenuation (SPOT and NORMAL lights only).
1927 .. attribute:: spotsize
1929 The cone angle of the spot light, in degrees (SPOT lights only).
1931 :type: float in [0 - 180].
1933 .. attribute:: spotblend
1935 Specifies the intensity distribution of the spot light (SPOT lights only).
1937 :type: float in [0 - 1]
1941 Higher values result in a more focused light source.
1943 .. class:: KX_MeshProxy(SCA_IObject)
1947 You can only change the vertex properties of a mesh object, not the mesh topology.
1949 To use mesh objects effectively, you should know a bit about how the game engine handles them.
1951 #. Mesh Objects are converted from Blender at scene load.
1952 #. The Converter groups polygons by Material. This means they can be sent to the renderer efficiently. A material holds:
1955 #. The Blender material.
1956 #. The Tile properties
1957 #. The face properties - (From the "Texture Face" panel)
1958 #. Transparency & z sorting
1960 #. Polygon shape (triangle/quad)
1963 #. Vertices will be split by face if necessary. Vertices can only be shared between faces if:
1965 #. They are at the same position
1966 #. UV coordinates are the same
1967 #. Their normals are the same (both polygons are "Set Smooth")
1968 #. They are the same color, for example: a cube has 24 vertices: 6 faces with 4 vertices per face.
1970 The correct method of iterating over every :class:`KX_VertexProxy` in a game object
1972 .. code-block:: python
1974 from bge import logic
1976 cont = logic.getCurrentController()
1979 for mesh in object.meshes:
1980 for m_index in range(len(mesh.materials)):
1981 for v_index in range(mesh.getVertexArrayLength(m_index)):
1982 vertex = mesh.getVertex(m_index, v_index)
1983 # Do something with vertex here...
1984 # ... eg: color the vertex red.
1985 vertex.color = [1.0, 0.0, 0.0, 1.0]
1987 .. attribute:: materials
1989 :type: list of :class:`KX_BlenderMaterial` or :class:`KX_PolygonMaterial` types
1991 .. attribute:: numPolygons
1995 .. attribute:: numMaterials
1999 .. method:: getMaterialName(matid)
2001 Gets the name of the specified material.
2003 :arg matid: the specified material.
2004 :type matid: integer
2005 :return: the attached material name.
2008 .. method:: getTextureName(matid)
2010 Gets the name of the specified material's texture.
2012 :arg matid: the specified material
2013 :type matid: integer
2014 :return: the attached material's texture name.
2017 .. method:: getVertexArrayLength(matid)
2019 Gets the length of the vertex array associated with the specified material.
2021 There is one vertex array for each material.
2023 :arg matid: the specified material
2024 :type matid: integer
2025 :return: the number of verticies in the vertex array.
2028 .. method:: getVertex(matid, index)
2030 Gets the specified vertex from the mesh object.
2032 :arg matid: the specified material
2033 :type matid: integer
2034 :arg index: the index into the vertex array.
2035 :type index: integer
2036 :return: a vertex object.
2037 :rtype: :class:`KX_VertexProxy`
2039 .. method:: getPolygon(index)
2041 Gets the specified polygon from the mesh.
2043 :arg index: polygon number
2044 :type index: integer
2045 :return: a polygon object.
2046 :rtype: :class:`PolyProxy`
2048 .. method:: transform(matid, matrix)
2050 Transforms the vertices of a mesh.
2052 :arg matid: material index, -1 transforms all.
2053 :type matid: integer
2054 :arg matrix: transformation matrix.
2055 :type matrix: 4x4 matrix [[float]]
2057 .. method:: transformUV(matid, matrix, uv_index=-1, uv_index_from=-1)
2059 Transforms the vertices UV's of a mesh.
2061 :arg matid: material index, -1 transforms all.
2062 :type matid: integer
2063 :arg matrix: transformation matrix.
2064 :type matrix: 4x4 matrix [[float]]
2065 :arg uv_index: optional uv index, -1 for all, otherwise 0 or 1.
2066 :type uv_index: integer
2067 :arg uv_index_from: optional uv index to copy from, -1 to transform the current uv.
2068 :type uv_index_from: integer
2070 .. class:: SCA_MouseSensor(SCA_ISensor)
2072 Mouse Sensor logic brick.
2074 .. attribute:: position
2076 current [x, y] coordinates of the mouse, in frame coordinates (pixels).
2078 :type: [integer, interger]
2086 * KX_MOUSESENSORMODE_LEFTBUTTON(1)
2087 * KX_MOUSESENSORMODE_MIDDLEBUTTON(2)
2088 * KX_MOUSESENSORMODE_RIGHTBUTTON(3)
2089 * KX_MOUSESENSORMODE_WHEELUP(4)
2090 * KX_MOUSESENSORMODE_WHEELDOWN(5)
2091 * KX_MOUSESENSORMODE_MOVEMENT(6)
2093 .. method:: getButtonStatus(button)
2095 Get the mouse button status.
2097 :arg button: The code that represents the key you want to get the state of, use one of :ref:`these constants<mouse-keys>`
2099 :return: The state of the given key, can be one of :ref:`these constants<input-status>`
2102 .. class:: KX_MouseFocusSensor(SCA_MouseSensor)
2104 The mouse focus sensor detects when the mouse is over the current game object.
2106 The mouse focus sensor works by transforming the mouse coordinates from 2d device
2107 space to 3d space then raycasting away from the camera.
2109 .. attribute:: raySource
2111 The worldspace source of the ray (the view position).
2113 :type: list (vector of 3 floats)
2115 .. attribute:: rayTarget
2117 The worldspace target of the ray.
2119 :type: list (vector of 3 floats)
2121 .. attribute:: rayDirection
2123 The :data:`rayTarget` - :class:`raySource` normalized.
2125 :type: list (normalized vector of 3 floats)
2127 .. attribute:: hitObject
2129 the last object the mouse was over.
2131 :type: :class:`KX_GameObject` or None
2133 .. attribute:: hitPosition
2135 The worldspace position of the ray intersecton.
2137 :type: list (vector of 3 floats)
2139 .. attribute:: hitNormal
2141 the worldspace normal from the face at point of intersection.
2143 :type: list (normalized vector of 3 floats)
2145 .. attribute:: hitUV
2147 the UV coordinates at the point of intersection.
2149 :type: list (vector of 2 floats)
2151 If the object has no UV mapping, it returns [0, 0].
2153 The UV coordinates are not normalized, they can be < 0 or > 1 depending on the UV mapping.
2155 .. attribute:: usePulseFocus
2157 When enabled, moving the mouse over a different object generates a pulse. (only used when the 'Mouse Over Any' sensor option is set).
2161 .. class:: KX_TouchSensor(SCA_ISensor)
2163 Touch sensor detects collisions between objects.
2165 .. attribute:: propName
2167 The property or material to collide with.
2171 .. attribute:: useMaterial
2173 Determines if the sensor is looking for a property or material. KX_True = Find material; KX_False = Find property.
2177 .. attribute:: usePulseCollision
2179 When enabled, changes to the set of colliding objects generate a pulse.
2183 .. attribute:: hitObject
2185 The last collided object. (read-only).
2187 :type: :class:`KX_GameObject` or None
2189 .. attribute:: hitObjectList
2191 A list of colliding objects. (read-only).
2193 :type: :class:`CListValue` of :class:`KX_GameObject`
2195 .. class:: KX_NearSensor(KX_TouchSensor)
2197 A near sensor is a specialised form of touch sensor.
2199 .. attribute:: distance
2201 The near sensor activates when an object is within this distance.
2205 .. attribute:: resetDistance
2207 The near sensor deactivates when the object exceeds this distance.
2211 .. class:: KX_NetworkMessageActuator(SCA_IActuator)
2215 .. attribute:: propName
2217 Messages will only be sent to objects with the given property name.
2221 .. attribute:: subject
2223 The subject field of the message.
2229 The body of the message.
2233 .. attribute:: usePropBody
2235 Send a property instead of a regular body message.
2239 .. class:: KX_NetworkMessageSensor(SCA_ISensor)
2241 The Message Sensor logic brick.
2243 Currently only loopback (local) networks are supported.
2245 .. attribute:: subject
2247 The subject the sensor is looking for.
2251 .. attribute:: frameMessageCount
2253 The number of messages received since the last frame. (read-only).
2257 .. attribute:: subjects
2259 The list of message subjects received. (read-only).
2261 :type: list of strings
2263 .. attribute:: bodies
2265 The list of message bodies received. (read-only).
2267 :type: list of strings
2270 .. class:: KX_FontObject(KX_GameObject)
2275 .. class:: KX_NavMeshObject(KX_GameObject)
2277 Python interface for using and controlling navigation meshes.
2279 .. method:: findPath(start, goal)
2281 Finds the path from start to goal points.
2283 :arg start: the start point
2284 :arg start: 3D Vector
2285 :arg goal: the goal point
2286 :arg start: 3D Vector
2287 :return: a path as a list of points
2288 :rtype: list of points
2290 .. method:: raycast(start, goal)
2292 Raycast from start to goal points.
2294 :arg start: the start point
2295 :arg start: 3D Vector
2296 :arg goal: the goal point
2297 :arg start: 3D Vector
2298 :return: the hit factor
2301 .. method:: draw(mode)
2303 Draws a debug mesh for the navigation mesh.
2305 :arg mode: the drawing mode (one of :ref:`these constants <navmesh-draw-mode>`)
2309 .. method:: rebuild()
2311 Rebuild the navigation mesh.
2315 .. class:: KX_ObjectActuator(SCA_IActuator)
2317 The object actuator ("Motion Actuator") applies force, torque, displacement, angular displacement,
2318 velocity, or angular velocity to an object.
2319 Servo control allows to regulate force to achieve a certain speed target.
2321 .. attribute:: force
2323 The force applied by the actuator.
2325 :type: list [x, y, z]
2327 .. attribute:: useLocalForce
2329 A flag specifying if the force is local.
2333 .. attribute:: torque
2335 The torque applied by the actuator.
2337 :type: list [x, y, z]
2339 .. attribute:: useLocalTorque
2341 A flag specifying if the torque is local.
2347 The displacement vector applied by the actuator.
2349 :type: list [x, y, z]
2351 .. attribute:: useLocalDLoc
2353 A flag specifying if the dLoc is local.
2359 The angular displacement vector applied by the actuator
2361 :type: list [x, y, z]
2365 Since the displacement is applied every frame, you must adjust the displacement based on the frame rate, or you game experience will depend on the player's computer speed.
2367 .. attribute:: useLocalDRot
2369 A flag specifying if the dRot is local.
2375 The linear velocity applied by the actuator.
2377 :type: list [x, y, z]
2379 .. attribute:: useLocalLinV
2381 A flag specifying if the linear velocity is local.
2387 This is the target speed for servo controllers.
2391 The angular velocity applied by the actuator.
2393 :type: list [x, y, z]
2395 .. attribute:: useLocalAngV
2397 A flag specifying if the angular velocity is local.
2401 .. attribute:: damping
2403 The damping parameter of the servo controller.
2407 .. attribute:: forceLimitX
2409 The min/max force limit along the X axis and activates or deactivates the limits in the servo controller.
2411 :type: list [min(float), max(float), bool]
2413 .. attribute:: forceLimitY
2415 The min/max force limit along the Y axis and activates or deactivates the limits in the servo controller.
2417 :type: list [min(float), max(float), bool]
2419 .. attribute:: forceLimitZ
2421 The min/max force limit along the Z axis and activates or deactivates the limits in the servo controller.
2423 :type: list [min(float), max(float), bool]
2427 The PID coefficients of the servo controller.
2429 :type: list of floats [proportional, integral, derivate]
2431 .. attribute:: reference
2433 The object that is used as reference to compute the velocity for the servo controller.
2435 :type: :class:`KX_GameObject` or None
2437 .. class:: KX_ParentActuator(SCA_IActuator)
2439 The parent actuator can set or remove an objects parent object.
2441 .. attribute:: object
2443 the object this actuator sets the parent too.
2445 :type: :class:`KX_GameObject` or None
2449 The mode of this actuator.
2451 :type: integer from 0 to 1.
2453 .. attribute:: compound
2455 Whether the object shape should be added to the parent compound shape when parenting.
2457 Effective only if the parent is already a compound shape.
2461 .. attribute:: ghost
2463 Whether the object should be made ghost when parenting
2464 Effective only if the shape is not added to the parent compound shape.
2468 .. class:: KX_PolyProxy(SCA_IObject)
2470 A polygon holds the index of the vertex forming the poylgon.
2473 The polygon attributes are read-only, you need to retrieve the vertex proxy if you want
2474 to change the vertex settings.
2476 .. attribute:: material_name
2478 The name of polygon material, empty if no material.
2482 .. attribute:: material
2484 The material of the polygon.
2486 :type: :class:`KX_PolygonMaterial` or :class:`KX_BlenderMaterial`
2488 .. attribute:: texture_name
2490 The texture name of the polygon.
2494 .. attribute:: material_id
2496 The material index of the polygon, use this to retrieve vertex proxy from mesh proxy.
2502 vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy.
2508 vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy.
2514 vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy.
2520 Vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
2521 Use this to retrieve vertex proxy from mesh proxy.
2525 .. attribute:: visible
2527 visible state of the polygon: 1=visible, 0=invisible.
2531 .. attribute:: collide
2533 collide state of the polygon: 1=receives collision, 0=collision free.
2537 .. method:: getMaterialName()
2539 Returns the polygon material name with MA prefix
2541 :return: material name
2544 .. method:: getMaterial()
2546 :return: The polygon material
2547 :rtype: :class:`KX_PolygonMaterial` or :class:`KX_BlenderMaterial`
2549 .. method:: getTextureName()
2551 :return: The texture name
2554 .. method:: getMaterialIndex()
2556 Returns the material bucket index of the polygon.
2557 This index and the ones returned by getVertexIndex() are needed to retrieve the vertex proxy from :class:`MeshProxy`.
2559 :return: the material index in the mesh
2562 .. method:: getNumVertex()
2564 Returns the number of vertex of the polygon.
2566 :return: number of vertex, 3 or 4.
2569 .. method:: isVisible()
2571 Returns whether the polygon is visible or not
2573 :return: 0=invisible, 1=visible
2576 .. method:: isCollider()
2578 Returns whether the polygon is receives collision or not
2580 :return: 0=collision free, 1=receives collision
2583 .. method:: getVertexIndex(vertex)
2585 Returns the mesh vertex index of a polygon vertex
2586 This index and the one returned by getMaterialIndex() are needed to retrieve the vertex proxy from :class:`MeshProxy`.
2588 :arg vertex: index of the vertex in the polygon: 0->3
2589 :arg vertex: integer
2590 :return: mesh vertex index
2593 .. method:: getMesh()
2595 Returns a mesh proxy
2598 :rtype: :class:`MeshProxy`
2600 .. class:: KX_PolygonMaterial(PyObjectPlus)
2602 This is the interface to materials in the game engine.
2604 Materials define the render state to be applied to mesh objects.
2608 Some of the methods/variables are CObjects. If you mix these up, you will crash blender.
2610 .. code-block:: python
2612 from bge import logic
2618 // original vertex position, no changes
2619 gl_Position = ftransform();
2620 // coordinate of the 1st texture channel
2621 gl_TexCoord[0] = gl_MultiTexCoord0;
2622 // coordinate of the 2nd texture channel
2623 gl_TexCoord[1] = gl_MultiTexCoord1;
2627 fragment_shader ="""
2629 uniform sampler2D color_0;
2630 uniform sampler2D color_1;
2631 uniform float factor;
2635 vec4 color_0 = texture2D(color_0, gl_TexCoord[0].st);
2636 vec4 color_1 = texture2D(color_1, gl_TexCoord[1].st);
2637 gl_FragColor = mix(color_0, color_1, factor);
2641 object = logic.getCurrentController().owner
2643 for mesh in object.meshes:
2644 for material in mesh.materials:
2645 shader = material.getShader()
2647 if not shader.isValid():
2648 shader.setSource(vertex_shader, fragment_shader, True)
2650 # get the first texture channel of the material
2651 shader.setSampler('color_0', 0)
2652 # get the second texture channel of the material
2653 shader.setSampler('color_1', 1)
2654 # pass another uniform to the shader
2655 shader.setUniform1f('factor', 0.3)
2658 .. attribute:: texture
2662 :type: string (read-only)
2664 .. attribute:: gl_texture
2666 OpenGL texture handle (eg for glBindTexture(GL_TEXTURE_2D, gl_texture).
2668 :type: integer (read-only)
2670 .. attribute:: material
2674 :type: string (read-only)
2676 .. attribute:: tface
2678 Texture face properties.
2680 :type: CObject (read-only)
2688 .. attribute:: tilexrep
2690 Number of tile repetitions in x direction.
2694 .. attribute:: tileyrep
2696 Number of tile repetitions in y direction.
2700 .. attribute:: drawingmode
2702 Drawing mode for the material.
2703 - 2 (drawingmode & 4) Textured
2704 - 4 (drawingmode & 16) Light
2705 - 14 (drawingmode & 16384) 3d Polygon Text.
2709 .. attribute:: transparent
2711 This material is transparent. All meshes with this
2712 material will be rendered after non transparent meshes from back
2717 .. attribute:: zsort
2719 Transparent polygons in meshes with this material will be sorted back to
2720 front before rendering.
2721 Non-Transparent polygons will be sorted front to back before rendering.
2725 .. attribute:: diffuse
2727 The diffuse color of the material. black = [0.0, 0.0, 0.0] white = [1.0, 1.0, 1.0].
2729 :type: list [r, g, b]
2731 .. attribute:: specular
2733 The specular color of the material. black = [0.0, 0.0, 0.0] white = [1.0, 1.0, 1.0].
2735 :type: list [r, g, b]
2737 .. attribute:: shininess
2739 The shininess (specular exponent) of the material. 0.0 <= shininess <= 128.0.
2743 .. attribute:: specularity
2745 The amount of specular of the material. 0.0 <= specularity <= 1.0.
2749 .. method:: updateTexture(tface, rasty)
2751 Updates a realtime animation.
2753 :arg tface: Texture face (eg mat.tface)
2754 :type tface: CObject
2755 :arg rasty: Rasterizer
2756 :type rasty: CObject
2758 .. method:: setTexture(tface)
2760 Sets texture render state.
2762 :arg tface: Texture face
2763 :type tface: CObject
2765 .. code-block:: python
2767 mat.setTexture(mat.tface)
2769 .. method:: activate(rasty, cachingInfo)
2771 Sets material parameters for this object for rendering.
2773 Material Parameters set:
2783 :arg rasty: Rasterizer instance.
2784 :type rasty: CObject
2785 :arg cachingInfo: Material cache instance.
2786 :type cachingInfo: CObject
2788 .. method:: setCustomMaterial(material)
2790 Sets the material state setup object.
2792 Using this method, you can extend or completely replace the gameengine material
2793 to do your own advanced multipass effects.
2795 Use this method to register your material class. Instead of the normal material,
2796 your class's activate method will be called just before rendering the mesh.
2797 This should setup the texture, material, and any other state you would like.
2798 It should return True to render the mesh, or False if you are finished. You should
2799 clean up any state Blender does not set before returning False.
2801 Activate Method Definition:
2803 .. code-block:: python
2805 def activate(self, rasty, cachingInfo, material):
2807 :arg material: The material object.
2808 :type material: instance
2810 .. code-block:: python
2816 def activate(self, rasty, cachingInfo, material):
2817 # Activate the material here.
2819 # The activate method will be called until it returns False.
2820 # Every time the activate method returns True the mesh will
2823 # rasty is a CObject for passing to material.updateTexture()
2824 # and material.activate()
2825 # cachingInfo is a CObject for passing to material.activate()
2826 # material is the KX_PolygonMaterial instance this material
2829 # default material properties:
2831 if self.pass_no == 0:
2832 material.activate(rasty, cachingInfo)
2833 # Return True to do this pass
2836 # clean up and return False to finish.
2840 # Create a new Python Material and pass it to the renderer.
2841 mat.setCustomMaterial(PyMaterial())
2843 .. class:: KX_RadarSensor(KX_NearSensor)
2845 Radar sensor is a near sensor with a conical sensor object.
2847 .. attribute:: coneOrigin
2849 The origin of the cone with which to test. The origin is in the middle of the cone. (read-only).
2851 :type: list of floats [x, y, z]
2853 .. attribute:: coneTarget
2855 The center of the bottom face of the cone with which to test. (read-only).
2857 :type: list of floats [x, y, z]
2859 .. attribute:: distance
2861 The height of the cone with which to test.
2865 .. attribute:: angle
2867 The angle of the cone (in degrees) with which to test.
2873 The axis on which the radar cone is cast.
2875 :type: integer from 0 to 5
2877 KX_RADAR_AXIS_POS_X, KX_RADAR_AXIS_POS_Y, KX_RADAR_AXIS_POS_Z,
2878 KX_RADAR_AXIS_NEG_X, KX_RADAR_AXIS_NEG_Y, KX_RADAR_AXIS_NEG_Z
2880 .. class:: KX_RaySensor(SCA_ISensor)
2882 A ray sensor detects the first object in a given direction.
2884 .. attribute:: propName
2886 The property the ray is looking for.
2890 .. attribute:: range
2892 The distance of the ray.
2896 .. attribute:: useMaterial
2898 Whether or not to look for a material (false = property).
2902 .. attribute:: useXRay
2904 Whether or not to use XRay.
2908 .. attribute:: hitObject
2910 The game object that was hit by the ray. (read-only).
2912 :type: :class:`KX_GameObject`
2914 .. attribute:: hitPosition
2916 The position (in worldcoordinates) where the object was hit by the ray. (read-only).
2918 :type: list [x, y, z]
2920 .. attribute:: hitNormal
2922 The normal (in worldcoordinates) of the object at the location where the object was hit by the ray. (read-only).
2924 :type: list [x, y, z]
2926 .. attribute:: rayDirection
2928 The direction from the ray (in worldcoordinates). (read-only).
2930 :type: list [x, y, z]
2934 The axis the ray is pointing on.
2936 :type: integer from 0 to 5
2945 .. class:: KX_SCA_AddObjectActuator(SCA_IActuator)
2947 Edit Object Actuator (in Add Object Mode)
2951 An Add Object actuator will be ignored if at game start, the linked object doesn't exist (or is empty) or the linked object is in an active layer.
2953 .. code-block:: none
2955 Error: GameObject 'Name' has a AddObjectActuator 'ActuatorName' without object (in 'nonactive' layer)
2957 .. attribute:: object
2959 the object this actuator adds.
2961 :type: :class:`KX_GameObject` or None
2963 .. attribute:: objectLastCreated
2965 the last added object from this actuator (read-only).
2967 :type: :class:`KX_GameObject` or None
2971 the lifetime of added objects, in frames. Set to 0 to disable automatic deletion.
2975 .. attribute:: linearVelocity
2977 the initial linear velocity of added objects.
2979 :type: list [vx, vy, vz]
2981 .. attribute:: angularVelocity
2983 the initial angular velocity of added objects.
2985 :type: list [vx, vy, vz]
2987 .. method:: instantAddObject()
2989 adds the object without needing to calling SCA_PythonController.activate()
2991 .. note:: Use objectLastCreated to get the newly created object.
2993 .. class:: KX_SCA_DynamicActuator(SCA_IActuator)
3001 the type of operation of the actuator, 0-4
3003 * KX_DYN_RESTORE_DYNAMICS(0)
3004 * KX_DYN_DISABLE_DYNAMICS(1)
3005 * KX_DYN_ENABLE_RIGID_BODY(2)
3006 * KX_DYN_DISABLE_RIGID_BODY(3)
3007 * KX_DYN_SET_MASS(4)
3011 the mass value for the KX_DYN_SET_MASS operation.
3015 .. class:: KX_SCA_EndObjectActuator(SCA_IActuator)
3017 Edit Object Actuator (in End Object mode)
3019 This actuator has no python methods.
3021 .. class:: KX_SCA_ReplaceMeshActuator(SCA_IActuator)
3023 Edit Object actuator, in Replace Mesh mode.
3027 Replace mesh actuators will be ignored if at game start, the named mesh doesn't exist.
3029 This will generate a warning in the console
3031 .. code-block:: none
3033 Error: GameObject 'Name' ReplaceMeshActuator 'ActuatorName' without object
3035 .. code-block:: python
3038 # Switch a game object's mesh based on its depth in the camera view.
3039 # +----------+ +-----------+ +-------------------------------------+
3040 # | Always +-----+ Python +-----+ Edit Object (Replace Mesh) LOD.Mesh |
3041 # +----------+ +-----------+ +-------------------------------------+
3042 from bge import logic
3044 # List detail meshes here
3045 # Mesh (name, near, far)
3046 # Meshes overlap so that they don't 'pop' when on the edge of the distance.
3047 meshes = ((".Hi", 0.0, -20.0),
3048 (".Med", -15.0, -50.0),
3049 (".Lo", -40.0, -100.0)
3052 cont = logic.getCurrentController()
3054 actuator = cont.actuators["LOD." + obj.name]
3055 camera = logic.getCurrentScene().active_camera
3057 def Depth(pos, plane):
3058 return pos[0]*plane[0] + pos[1]*plane[1] + pos[2]*plane[2] + plane[3]
3060 # Depth is negative and decreasing further from the camera
3061 depth = Depth(object.position, camera.world_to_camera[2])
3065 # Find the lowest detail mesh for depth
3067 if depth < mesh[1] and depth > mesh[2]:
3069 if "ME" + object.name + mesh[0] == actuator.getMesh():
3072 if newmesh != None and "ME" + object.name + newmesh[0] != actuator.mesh:
3073 # The mesh is a different mesh - switch it.
3074 # Check the current mesh is not a better fit.
3075 if curmesh == None or curmesh[1] < depth or curmesh[2] > depth:
3076 actuator.mesh = object.name + newmesh[0]
3077 cont.activate(actuator)
3081 :class:`MeshProxy` or the name of the mesh that will replace the current one.
3083 Set to None to disable actuator.
3085 :type: :class:`MeshProxy` or None if no mesh is set
3087 .. attribute:: useDisplayMesh
3089 when true the displayed mesh is replaced.
3093 .. attribute:: usePhysicsMesh
3095 when true the physics mesh is replaced.
3099 .. method:: instantReplaceMesh()
3101 Immediately replace mesh without delay.
3103 .. class:: KX_Scene(PyObjectPlus)
3105 An active scene that gives access to objects, cameras, lights and scene attributes.
3107 The activity culling stuff is supposed to disable logic bricks when their owner gets too far
3108 from the active camera. It was taken from some code lurking at the back of KX_Scene - who knows
3111 .. code-block:: python
3113 from bge import logic
3116 scene = logic.getCurrentScene()
3118 # print all the objects in the scene
3119 for object in scene.objects:
3122 # get an object named 'Cube'
3123 object = scene.objects["Cube"]
3125 # get the first object in the scene.
3126 object = scene.objects[0]
3128 .. code-block:: python
3130 # Get the depth of an object in the camera view.
3131 from bge import logic
3133 object = logic.getCurrentController().owner
3134 cam = logic.getCurrentScene().active_camera
3136 # Depth is negative and decreasing further from the camera
3137 depth = object.position[0]*cam.world_to_camera[2][0] + object.position[1]*cam.world_to_camera[2][1] + object.position[2]*cam.world_to_camera[2][2] + cam.world_to_camera[2][3]
3139 @bug: All attributes are read only at the moment.
3143 The scene's name, (read-only).
3147 .. attribute:: objects
3149 A list of objects in the scene, (read-only).
3151 :type: :class:`CListValue` of :class:`KX_GameObject`
3153 .. attribute:: objectsInactive
3155 A list of objects on background layers (used for the addObject actuator), (read-only).
3157 :type: :class:`CListValue` of :class:`KX_GameObject`
3159 .. attribute:: lights
3161 A list of lights in the scene, (read-only).
3163 :type: :class:`CListValue` of :class:`KX_LightObject`
3165 .. attribute:: cameras
3167 A list of cameras in the scene, (read-only).
3169 :type: :class:`CListValue` of :class:`KX_Camera`
3171 .. attribute:: active_camera
3173 The current active camera.
3175 :type: :class:`KX_Camera`
3179 This can be set directly from python to avoid using the :class:`KX_SceneActuator`.
3181 .. attribute:: suspended
3183 True if the scene is suspended, (read-only).
3187 .. attribute:: activity_culling
3189 True if the scene is activity culling.
3193 .. attribute:: activity_culling_radius
3195 The distance outside which to do activity culling. Measured in manhattan distance.
3199 .. attribute:: dbvt_culling
3201 True when Dynamic Bounding box Volume Tree is set (read-only).
3205 .. attribute:: pre_draw
3207 A list of callables to be run before the render step.
3211 .. attribute:: post_draw
3213 A list of callables to be run after the render step.
3217 .. attribute:: gravity
3219 The scene gravity using the world x, y and z axis.
3221 :type: list [fx, fy, fz]
3223 .. method:: addObject(object, other, time=0)
3225 Adds an object to the scene like the Add Object Actuator would.
3227 :arg object: The object to add
3228 :type object: :class:`KX_GameObject` or string
3229 :arg other: The object's center to use when adding the object
3230 :type other: :class:`KX_GameObject` or string
3231 :arg time: The lifetime of the added object, in frames. A time of 0 means the object will last forever.
3233 :return: The newly added object.
3234 :rtype: :class:`KX_GameObject`
3238 Removes the scene from the game.
3240 .. method:: restart()
3244 .. method:: replace(scene)
3246 Replaces this scene with another one.
3248 :arg scene: The name of the scene to replace this scene with.
3251 .. method:: suspend()
3253 Suspends this scene.
3255 .. method:: resume()
3259 .. method:: get(key, default=None)
3261 Return the value matching key, or the default value if its not found.
3262 :return: The key value or a default.
3264 .. method:: drawObstacleSimulation()
3266 Draw debug visualization of obstacle simulation.
3268 .. class:: KX_SceneActuator(SCA_IActuator)
3270 Scene Actuator logic brick.
3274 Scene actuators that use a scene name will be ignored if at game start, the named scene doesn't exist or is empty
3276 This will generate a warning in the console:
3278 .. code-block:: none
3280 Error: GameObject 'Name' has a SceneActuator 'ActuatorName' (SetScene) without scene
3282 .. attribute:: scene
3284 the name of the scene to change to/overlay/underlay/remove/suspend/resume.
3288 .. attribute:: camera
3290 the camera to change to.
3292 :type: :class:`KX_Camera` on read, string or :class:`KX_Camera` on write
3296 When setting the attribute, you can use either a :class:`KX_Camera` or the name of the camera.
3298 .. attribute:: useRestart
3300 Set flag to True to restart the sene.
3306 The mode of the actuator.
3308 :type: integer from 0 to 5.
3310 .. class:: KX_SoundActuator(SCA_IActuator)
3314 The :data:`startSound`, :data:`pauseSound` and :data:`stopSound` do not require the actuator to be activated - they act instantly provided that the actuator has been activated once at least.
3316 .. attribute:: volume
3318 The volume (gain) of the sound.
3324 The current position in the audio stream (in seconds).
3328 .. attribute:: pitch
3330 The pitch of the sound.
3336 The operation mode of the actuator. Can be one of :ref:`these constants<logic-sound-actuator>`
3340 .. attribute:: sound
3342 The sound the actuator should play.
3344 :type: Audaspace factory
3348 Whether or not the actuator should be using 3D sound. (read-only)
3352 .. attribute:: volume_maximum
3354 The maximum gain of the sound, no matter how near it is.
3358 .. attribute:: volume_minimum
3360 The minimum gain of the sound, no matter how far it is away.
3364 .. attribute:: distance_reference
3366 The distance where the sound has a gain of 1.0.
3370 .. attribute:: distance_maximum
3372 The maximum distance at which you can hear the sound.
3376 .. attribute:: attenuation
3378 The influence factor on volume depending on distance.
3382 .. attribute:: cone_angle_inner
3384 The angle of the inner cone.
3388 .. attribute:: cone_angle_outer
3390 The angle of the outer cone.
3394 .. attribute:: cone_volume_outer
3396 The gain outside the outer cone (the gain in the outer cone will be interpolated between this value and the normal gain in the inner cone).
3400 .. method:: startSound()
3406 .. method:: pauseSound()
3412 .. method:: stopSound()
3418 .. class:: KX_StateActuator(SCA_IActuator)
3420 State actuator changes the state mask of parent object.
3422 .. attribute:: operation
3424 Type of bit operation to be applied on object state mask.
3426 You can use one of :ref:`these constants <state-actuator-operation>`
3432 Value that defines the bits that will be modified by the operation.
3434 The bits that are 1 in the mask will be updated in the object state.
3436 The bits that are 0 are will be left unmodified expect for the Copy operation which copies the mask to the object state.
3440 .. class:: KX_TrackToActuator(SCA_IActuator)
3442 Edit Object actuator in Track To mode.
3446 Track To Actuators will be ignored if at game start, the object to track to is invalid.
3448 This will generate a warning in the console:
3450 .. code-block:: none
3452 GameObject 'Name' no object in EditObjectActuator 'ActuatorName'
3454 .. attribute:: object
3456 the object this actuator tracks.
3458 :type: :class:`KX_GameObject` or None
3462 the time in frames with which to delay the tracking motion.
3466 .. attribute:: use3D
3468 the tracking motion to use 3D.
3472 .. class:: KX_VehicleWrapper(PyObjectPlus)
3478 .. method:: addWheel(wheel, attachPos, attachDir, axleDir, suspensionRestLength, wheelRadius, hasSteering)
3480 Add a wheel to the vehicle
3482 :arg wheel: The object to use as a wheel.
3483 :type wheel: :class:`KX_GameObject` or a KX_GameObject name
3484 :arg attachPos: The position that this wheel will attach to.
3485 :type attachPos: vector of 3 floats
3486 :arg attachDir: The direction this wheel points.
3487 :type attachDir: vector of 3 floats
3488 :arg axleDir: The direction of this wheels axle.
3489 :type axleDir: vector of 3 floats
3490 :arg suspensionRestLength: TODO - Description
3491 :type suspensionRestLength: float
3492 :arg wheelRadius: The size of the wheel.
3493 :type wheelRadius: float
3495 .. method:: applyBraking(force, wheelIndex)
3497 Apply a braking force to the specified wheel
3499 :arg force: the brake force
3502 :arg wheelIndex: index of the wheel where the force needs to be applied
3503 :type wheelIndex: integer
3505 .. method:: applyEngineForce(force, wheelIndex)
3507 Apply an engine force to the specified wheel
3509 :arg force: the engine force
3512 :arg wheelIndex: index of the wheel where the force needs to be applied
3513 :type wheelIndex: integer
3515 .. method:: getConstraintId()
3517 Get the constraint ID
3519 :return: the constraint id
3522 .. method:: getConstraintType()
3524 Returns the constraint type.
3526 :return: constraint type
3529 .. method:: getNumWheels()
3531 Returns the number of wheels.
3533 :return: the number of wheels for this vehicle
3536 .. method:: getWheelOrientationQuaternion(wheelIndex)
3538 Returns the wheel orientation as a quaternion.
3540 :arg wheelIndex: the wheel index
3541 :type wheelIndex: integer
3543 :return: TODO Description
3544 :rtype: TODO - type should be quat as per method name but from the code it looks like a matrix
3546 .. method:: getWheelPosition(wheelIndex)
3548 Returns the position of the specified wheel
3550 :arg wheelIndex: the wheel index
3551 :type wheelIndex: integer
3552 :return: position vector
3553 :rtype: list[x, y, z]
3555 .. method:: getWheelRotation(wheelIndex)
3557 Returns the rotation of the specified wheel
3559 :arg wheelIndex: the wheel index
3560 :type wheelIndex: integer
3562 :return: the wheel rotation
3565 .. method:: setRollInfluence(rollInfluece, wheelIndex)
3567 Set the specified wheel's roll influence.
3568 The higher the roll influence the more the vehicle will tend to roll over in corners.
3570 :arg rollInfluece: the wheel roll influence
3571 :type rollInfluece: float
3573 :arg wheelIndex: the wheel index
3574 :type wheelIndex: integer
3576 .. method:: setSteeringValue(steering, wheelIndex)
3578 Set the specified wheel's steering
3580 :arg steering: the wheel steering
3581 :type steering: float
3583 :arg wheelIndex: the wheel index
3584 :type wheelIndex: integer
3586 .. method:: setSuspensionCompression(compression, wheelIndex)
3588 Set the specified wheel's compression
3590 :arg compression: the wheel compression
3591 :type compression: float
3593 :arg wheelIndex: the wheel index
3594 :type wheelIndex: integer
3596 .. method:: setSuspensionDamping(damping, wheelIndex)
3598 Set the specified wheel's damping
3600 :arg damping: the wheel damping
3601 :type damping: float
3603 :arg wheelIndex: the wheel index
3604 :type wheelIndex: integer
3606 .. method:: setSuspensionStiffness(stiffness, wheelIndex)
3608 Set the specified wheel's stiffness
3610 :arg stiffness: the wheel stiffness
3611 :type stiffness: float
3613 :arg wheelIndex: the wheel index
3614 :type wheelIndex: integer
3616 .. method:: setTyreFriction(friction, wheelIndex)
3618 Set the specified wheel's tyre friction
3620 :arg friction: the tyre friction
3621 :type friction: float
3623 :arg wheelIndex: the wheel index
3624 :type wheelIndex: integer
3626 .. class:: KX_CharacterWrapper(PyObjectPlus)
3628 A wrapper to expose character physics options.
3630 .. attribute:: onGround
3632 Whether or not the character is on the ground. (read-only)
3636 .. attribute:: gravity
3638 The gravity value used for the character.
3644 The character jumps based on it's jump speed.
3646 .. class:: KX_VertexProxy(SCA_IObject)
3648 A vertex holds position, UV, color and normal information.
3651 The physics simulation is NOT currently updated - physics will not respond
3652 to changes in the vertex position.
3656 The position of the vertex.
3658 :type: list [x, y, z]
3662 The texture coordinates of the vertex.
3666 .. attribute:: normal
3668 The normal of the vertex.
3670 :type: list [nx, ny, nz]
3672 .. attribute:: color
3674 The color of the vertex.
3676 :type: list [r, g, b, a]
3678 Black = [0.0, 0.0, 0.0, 1.0], White = [1.0, 1.0, 1.0, 1.0]
3682 The x coordinate of the vertex.
3688 The y coordinate of the vertex.
3694 The z coordinate of the vertex.
3700 The u texture coordinate of the vertex.
3706 The v texture coordinate of the vertex.
3712 The second u texture coordinate of the vertex.
3718 The second v texture coordinate of the vertex.
3724 The red component of the vertex color. 0.0 <= r <= 1.0.
3730 The green component of the vertex color. 0.0 <= g <= 1.0.
3736 The blue component of the vertex color. 0.0 <= b <= 1.0.
3742 The alpha component of the vertex color. 0.0 <= a <= 1.0.
3746 .. method:: getXYZ()
3748 Gets the position of this vertex.
3750 :return: this vertexes position in local coordinates.
3751 :rtype: list [x, y, z]
3753 .. method:: setXYZ(pos)
3755 Sets the position of this vertex.
3757 :type: list [x, y, z]
3759 :arg pos: the new position for this vertex in local coordinates.
3763 Gets the UV (texture) coordinates of this vertex.
3765 :return: this vertexes UV (texture) coordinates.
3768 .. method:: setUV(uv)
3770 Sets the UV (texture) coordinates of this vertex.
3774 .. method:: getUV2()
3776 Gets the 2nd UV (texture) coordinates of this vertex.
3778 :return: this vertexes UV (texture) coordinates.
3781 .. method:: setUV2(uv, unit)
3783 Sets the 2nd UV (texture) coordinates of this vertex.
3787 :arg unit: optional argument, FLAT==1, SECOND_UV==2, defaults to SECOND_UV
3790 .. method:: getRGBA()
3792 Gets the color of this vertex.
3794 The color is represented as four bytes packed into an integer value. The color is
3797 Since Python offers no way to get each byte without shifting, you must use the struct module to
3798 access color in an machine independent way.
3800 Because of this, it is suggested you use the r, g, b and a attributes or the color attribute instead.
3802 .. code-block:: python
3805 col = struct.unpack('4B', struct.pack('I', v.getRGBA()))
3806 # col = (r, g, b, a)
3807 # black = ( 0, 0, 0, 255)
3808 # white = (255, 255, 255, 255)
3810 :return: packed color. 4 byte integer with one byte per color channel in RGBA format.
3813 .. method:: setRGBA(col)
3815 Sets the color of this vertex.
3817 See getRGBA() for the format of col, and its relevant problems. Use the r, g, b and a attributes
3818 or the color attribute instead.
3820 setRGBA() also accepts a four component list as argument col. The list represents the color as [r, g, b, a]
3821 with black = [0.0, 0.0, 0.0, 1.0] and white = [1.0, 1.0, 1.0, 1.0]
3823 .. code-block:: python
3825 v.setRGBA(0xff0000ff) # Red
3826 v.setRGBA(0xff00ff00) # Green on little endian, transparent purple on big endian
3827 v.setRGBA([1.0, 0.0, 0.0, 1.0]) # Red
3828 v.setRGBA([0.0, 1.0, 0.0, 1.0]) # Green on all platforms.
3830 :arg col: the new color of this vertex in packed RGBA format.
3831 :type col: integer or list [r, g, b, a]
3833 .. method:: getNormal()
3835 Gets the normal vector of this vertex.
3837 :return: normalized normal vector.
3838 :rtype: list [nx, ny, nz]
3840 .. method:: setNormal(normal)
3842 Sets the normal vector of this vertex.
3844 :type: sequence of floats [r, g, b]
3846 :arg normal: the new normal of this vertex.
3848 .. class:: KX_VisibilityActuator(SCA_IActuator)
3850 Visibility Actuator.
3852 .. attribute:: visibility
3854 whether the actuator makes its parent object visible or invisible.
3858 .. attribute:: useOcclusion
3860 whether the actuator makes its parent object an occluder or not.
3864 .. attribute:: useRecursion
3866 whether the visibility/occlusion should be propagated to all children of the object.
3870 .. class:: SCA_2DFilterActuator(SCA_IActuator)
3872 Create, enable and disable 2D filters
3874 The following properties don't have an immediate effect.
3875 You must active the actuator to get the result.
3876 The actuator is not persistent: it automatically stops itself after setting up the filter
3877 but the filter remains active. To stop a filter you must activate the actuator with 'type'
3878 set to :data:`~bge.logic.RAS_2DFILTER_DISABLED` or :data:`~bge.logic.RAS_2DFILTER_NOFILTER`.
3880 .. attribute:: shaderText
3882 shader source code for custom shader.
3886 .. attribute:: disableMotionBlur
3888 action on motion blur: 0=enable, 1=disable.
3894 Type of 2D filter, use one of :ref:`these constants <Two-D-FilterActuator-mode>`
3898 .. attribute:: passNumber
3900 order number of filter in the stack of 2D filters. Filters are executed in increasing order of passNb.
3902 Only be one filter can be defined per passNb.
3904 :type: integer (0-100)
3906 .. attribute:: value
3908 argument for motion blur filter.
3910 :type: float (0.0-100.0)
3912 .. class:: SCA_ANDController(SCA_IController)
3914 An AND controller activates only when all linked sensors are activated.
3916 There are no special python methods for this controller.
3918 .. class:: SCA_ActuatorSensor(SCA_ISensor)
3920 Actuator sensor detect change in actuator state of the parent object.
3921 It generates a positive pulse if the corresponding actuator is activated
3922 and a negative pulse if the actuator is deactivated.
3924 .. attribute:: actuator
3926 the name of the actuator that the sensor is monitoring.
3930 .. class:: SCA_AlwaysSensor(SCA_ISensor)
3932 This sensor is always activated.
3934 .. class:: SCA_DelaySensor(SCA_ISensor)
3936 The Delay sensor generates positive and negative triggers at precise time,
3937 expressed in number of frames. The delay parameter defines the length of the initial OFF period. A positive trigger is generated at the end of this period.
3939 The duration parameter defines the length of the ON period following the OFF period.
3940 There is a negative trigger at the end of the ON period. If duration is 0, the sensor stays ON and there is no negative trigger.
3942 The sensor runs the OFF-ON cycle once unless the repeat option is set: the OFF-ON cycle repeats indefinately (or the OFF cycle if duration is 0).
3944 Use :class:`SCA_ISensor.reset` at any time to restart sensor.
3946 .. attribute:: delay