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:: status
210 The status of the sensor (read-only): can be one of :ref:`these constants<sensor-status>`.
216 This convenient attribute combines the values of triggered and positive attributes.
220 Reset sensor internal state, effect depends on the type of sensor and settings.
222 The sensor is put in its initial state as if it was just activated.
224 .. class:: SCA_IController(SCA_ILogicBrick)
226 Base class for all controller logic bricks.
230 The controllers state bitmask. This can be used with the GameObject's state to test if the controller is active.
234 .. attribute:: sensors
236 A list of sensors linked to this controller.
238 :type: sequence supporting index/string lookups and iteration.
242 The sensors are not necessarily owned by the same object.
246 When objects are instanced in dupligroups links may be lost from objects outside the dupligroup.
248 .. attribute:: actuators
250 A list of actuators linked to this controller.
252 :type: sequence supporting index/string lookups and iteration.
256 The sensors are not necessarily owned by the same object.
260 When objects are instanced in dupligroups links may be lost from objects outside the dupligroup.
262 .. attribute:: useHighPriority
264 When set the controller executes always before all other controllers that dont have this set.
270 Order of execution between high priority controllers is not guaranteed.
272 .. class:: SCA_IActuator(SCA_ILogicBrick)
274 Base class for all actuator logic bricks.
276 .. class:: BL_ActionActuator(SCA_IActuator)
278 Action Actuators apply an action to an actor.
280 .. attribute:: action
282 The name of the action to set as the current action.
286 .. attribute:: frameStart
288 Specifies the starting frame of the animation.
292 .. attribute:: frameEnd
294 Specifies the ending frame of the animation.
298 .. attribute:: blendIn
300 Specifies the number of frames of animation to generate when making transitions between actions.
304 .. attribute:: priority
306 Sets the priority of this actuator. Actuators will lower priority numbers will override actuators with higher numbers.
312 Sets the current frame for the animation.
316 .. attribute:: propName
318 Sets the property to be used in FromProp playback mode.
322 .. attribute:: blendTime
324 Sets the internal frame timer. This property must be in the range from 0.0 to blendIn.
330 The operation mode of the actuator. Can be one of :ref:`these constants<action-actuator>`.
334 .. attribute:: useContinue
336 The actions continue option, True or False. When True, the action will always play from where last left off,
337 otherwise negative events to this actuator will reset it to its start frame.
341 .. attribute:: framePropName
343 The name of the property that is set to the current frame number.
347 .. class:: BL_Shader(PyObjectPlus)
349 BL_Shader GLSL shaders.
353 .. method:: setUniformfv(name, fList)
355 Set a uniform with a list of float values
357 :arg name: the uniform name
359 :arg fList: a list (2, 3 or 4 elements) of float values
360 :type fList: list[float]
362 .. method:: delSource()
364 Clear the shader. Use this method before the source is changed with :data:`setSource`.
366 .. method:: getFragmentProg()
368 Returns the fragment program.
370 :return: The fragment program.
373 .. method:: getVertexProg()
375 Get the vertex program.
377 :return: The vertex program.
380 .. method:: isValid()
382 Check if the shader is valid.
384 :return: True if the shader is valid
387 .. method:: setAttrib(enum)
389 Set attribute location. (The parameter is ignored a.t.m. and the value of "tangent" is always used.)
391 :arg enum: attribute location value
394 .. method:: setNumberOfPasses( max_pass )
396 Set the maximum number of passes. Not used a.t.m.
398 :arg max_pass: the maximum number of passes
399 :type max_pass: integer
401 .. method:: setSampler(name, index)
403 Set uniform texture sample index.
405 :arg name: Uniform name
407 :arg index: Texture sample index.
410 .. method:: setSource(vertexProgram, fragmentProgram)
412 Set the vertex and fragment programs
414 :arg vertexProgram: Vertex program
415 :type vertexProgram: string
416 :arg fragmentProgram: Fragment program
417 :type fragmentProgram: string
419 .. method:: setUniform1f(name, fx)
421 Set a uniform with 1 float value.
423 :arg name: the uniform name
425 :arg fx: Uniform value
428 .. method:: setUniform1i(name, ix)
430 Set a uniform with an integer value.
432 :arg name: the uniform name
434 :arg ix: the uniform value
437 .. method:: setUniform2f(name, fx, fy)
439 Set a uniform with 2 float values
441 :arg name: the uniform name
443 :arg fx: first float value
446 :arg fy: second float value
449 .. method:: setUniform2i(name, ix, iy)
451 Set a uniform with 2 integer values
453 :arg name: the uniform name
455 :arg ix: first integer value
457 :arg iy: second integer value
460 .. method:: setUniform3f(name, fx, fy, fz)
462 Set a uniform with 3 float values.
464 :arg name: the uniform name
466 :arg fx: first float value
468 :arg fy: second float value
470 :arg fz: third float value
473 .. method:: setUniform3i(name, ix, iy, iz)
475 Set a uniform with 3 integer values
477 :arg name: the uniform name
479 :arg ix: first integer value
481 :arg iy: second integer value
483 :arg iz: third integer value
486 .. method:: setUniform4f(name, fx, fy, fz, fw)
488 Set a uniform with 4 float values.
490 :arg name: the uniform name
492 :arg fx: first float value
494 :arg fy: second float value
496 :arg fz: third float value
498 :arg fw: fourth float value
501 .. method:: setUniform4i(name, ix, iy, iz, iw)
503 Set a uniform with 4 integer values
505 :arg name: the uniform name
507 :arg ix: first integer value
509 :arg iy: second integer value
511 :arg iz: third integer value
513 :arg iw: fourth integer value
516 .. method:: setUniformDef(name, type)
520 :arg name: the uniform name
522 :arg type: uniform type
523 :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
525 .. method:: setUniformMatrix3(name, mat, transpose)
527 Set a uniform with a 3x3 matrix value
529 :arg name: the uniform name
531 :arg mat: A 3x3 matrix [[f, f, f], [f, f, f], [f, f, f]]
532 :type mat: 3x3 matrix
533 :arg transpose: set to True to transpose the matrix
534 :type transpose: boolean
536 .. method:: setUniformMatrix4(name, mat, transpose)
538 Set a uniform with a 4x4 matrix value
540 :arg name: the uniform name
542 :arg mat: A 4x4 matrix [[f, f, f, f], [f, f, f, f], [f, f, f, f], [f, f, f, f]]
543 :type mat: 4x4 matrix
544 :arg transpose: set to True to transpose the matrix
545 :type transpose: boolean
547 .. method:: setUniformiv(name, iList)
549 Set a uniform with a list of integer values
551 :arg name: the uniform name
553 :arg iList: a list (2, 3 or 4 elements) of integer values
554 :type iList: list[integer]
556 .. method:: validate()
558 Validate the shader object.
560 .. class:: BL_ShapeActionActuator(SCA_IActuator)
562 ShapeAction Actuators apply an shape action to an mesh object.
564 .. attribute:: action
566 The name of the action to set as the current shape action.
570 .. attribute:: frameStart
572 Specifies the starting frame of the shape animation.
576 .. attribute:: frameEnd
578 Specifies the ending frame of the shape animation.
582 .. attribute:: blendIn
584 Specifies the number of frames of animation to generate when making transitions between actions.
588 .. attribute:: priority
590 Sets the priority of this actuator. Actuators will lower priority numbers will override actuators with higher numbers.
596 Sets the current frame for the animation.
600 .. attribute:: propName
602 Sets the property to be used in FromProp playback mode.
606 .. attribute:: blendTime
608 Sets the internal frame timer. This property must be in the range from 0.0 to blendin.
614 The operation mode of the actuator. Can be one of :ref:`these constants<shape-action-actuator>`.
618 .. attribute:: framePropName
620 The name of the property that is set to the current frame number.
624 .. class:: CListValue(CPropValue)
626 This is a list like object used in the game engine internally that behaves similar to a python list in most ways.
628 As well as the normal index lookup (``val= clist[i]``), CListValue supports string lookups (``val= scene.objects["Cube"]``)
630 Other operations such as ``len(clist)``, ``list(clist)``, ``clist[0:10]`` are also supported.
632 .. method:: append(val)
634 Add an item to the list (like pythons append)
638 Appending values to the list can cause crashes when the list is used internally by the game engine.
640 .. method:: count(val)
642 Count the number of instances of a value in the list.
644 :return: number of instances
647 .. method:: index(val)
649 Return the index of a value in the list.
651 :return: The index of the value in the list.
654 .. method:: reverse()
656 Reverse the order of the list.
658 .. method:: get(key, default=None)
660 Return the value matching key, or the default value if its not found.
662 :return: The key value or a default.
664 .. method:: from_id(id)
666 This is a funtion especially for the game engine to return a value with a spesific id.
668 Since object names are not always unique, the id of an object can be used to get an object from the CValueList.
672 .. code-block:: python
674 myObID=id(gameObject)
675 ob= scene.objects.from_id(myObID)
677 Where ``myObID`` is an int or long from the id function.
679 This has the advantage that you can store the id in places you could not store a gameObject.
683 The id is derived from a memory location and will be different each time the game engine starts.
685 .. class:: KX_BlenderMaterial(PyObjectPlus)
689 .. method:: getShader()
691 Returns the material's shader.
693 :return: the material's shader
694 :rtype: :class:`BL_Shader`
696 .. method:: setBlending(src, dest)
698 Set the pixel color arithmetic functions.
700 :arg src: Specifies how the red, green, blue, and alpha source blending factors are computed.
701 :type src: Value in...
706 * GL_ONE_MINUS_SRC_COLOR,
708 * GL_ONE_MINUS_DST_COLOR,
710 * GL_ONE_MINUS_SRC_ALPHA,
712 * GL_ONE_MINUS_DST_ALPHA,
713 * GL_SRC_ALPHA_SATURATE
715 :arg dest: Specifies how the red, green, blue, and alpha destination blending factors are computed.
716 :type dest: Value in...
721 * GL_ONE_MINUS_SRC_COLOR
723 * GL_ONE_MINUS_DST_COLOR
725 * GL_ONE_MINUS_SRC_ALPHA
727 * GL_ONE_MINUS_DST_ALPHA
728 * GL_SRC_ALPHA_SATURATE
730 .. method:: getMaterialIndex()
732 Returns the material's index.
734 :return: the material's index
737 .. class:: KX_CameraActuator(SCA_IActuator)
739 Applies changes to a camera.
741 .. attribute:: damping
743 strength of of the camera following movement.
749 minimum distance to the target object maintained by the actuator.
755 maximum distance to stay from the target object.
759 .. attribute:: height
761 height to stay above the target object.
767 axis this actuator is tracking, True=X, False=Y.
771 .. attribute:: object
773 the object this actuator tracks.
775 :type: :class:`KX_GameObject` or None
777 .. class:: KX_ConstraintActuator(SCA_IActuator)
779 A constraint actuator limits the position, rotation, distance or orientation of an object.
783 Time constant of the constraint expressed in frame (not use by Force field constraint).
787 .. attribute:: rotDamp
789 Time constant for the rotation expressed in frame (only for the distance constraint), 0 = use damp for rotation as well.
793 .. attribute:: direction
795 The reference direction in world coordinate for the orientation constraint.
797 :type: 3-tuple of float: (x, y, z)
799 .. attribute:: option
801 Binary combination of :ref:`these constants <constraint-actuator-option>`
807 activation time of the actuator. The actuator disables itself after this many frame. If set to 0, the actuator is not limited in time.
811 .. attribute:: propName
813 the name of the property or material for the ray detection of the distance constraint.
819 The lower bound of the constraint. For the rotation and orientation constraint, it represents radiant.
823 .. attribute:: distance
825 the target distance of the distance constraint.
831 the upper bound of the constraint. For rotation and orientation constraints, it represents radiant.
835 .. attribute:: rayLength
837 the length of the ray of the distance constraint.
843 type of constraint. Use one of the :ref:`these constants <constraint-actuator-limit>`
848 .. class:: KX_ConstraintWrapper(PyObjectPlus)
852 .. method:: getConstraintId(val)
854 Returns the contraint's ID
856 :return: the constraint's ID
859 .. class:: KX_GameActuator(SCA_IActuator)
861 The game actuator loads a new .blend file, restarts the current .blend file or quits the game.
863 .. attribute:: fileName
865 the new .blend file to load.
871 The mode of this actuator. Can be on of :ref:`these constants <game-actuator>`
875 .. class:: KX_GameObject(SCA_IObject)
877 All game objects are derived from this class.
879 Properties assigned to game objects are accessible as attributes of this class.
883 Calling ANY method or attribute on an object that has been removed from a scene will raise a SystemError,
884 if an object may have been removed since last accessing it use the :data:`invalid` attribute to check.
886 KX_GameObject can be subclassed to extend functionality. For example:
888 .. code-block:: python
892 class CustomGameObject(bge.types.KX_GameObject):
895 def __init__(self, old_owner):
896 # "old_owner" can just be ignored. At this point, "self" is
897 # already the object in the scene, and "old_owner" has been
900 # New attributes can be defined - but we could also use a game
901 # property, like "self['rate']".
902 self.rate = CustomGameObject.RATE
905 self.worldPosition.z += self.rate
908 if self.worldPosition.z > 1.0:
909 self.rate = -CustomGameObject.RATE
910 elif self.worldPosition.z < 0.0:
911 self.rate = CustomGameObject.RATE
915 old_object = cont.owner
916 mutated_object = CustomGameObject(cont.owner)
918 # After calling the constructor above, references to the old object
919 # should not be used.
920 assert(old_object is not mutated_object)
921 assert(old_object.invalid)
922 assert(mutated_object is cont.owner)
924 # Called later - note we are now working with the mutated object.
928 When subclassing objects other than empties and meshes, the specific type
929 should be used - e.g. inherit from :class:`BL_ArmatureObject` when the object
930 to mutate is an armature.
934 The object's name. (read-only).
946 The object must have a physics controller for the mass to be applied, otherwise the mass value will be returned as 0.0.
948 .. attribute:: linVelocityMin
950 Enforces the object keeps moving at a minimum velocity.
956 Applies to dynamic and rigid body objects only.
960 A value of 0.0 disables this option.
964 While objects are stationary the minimum velocity will not be applied.
966 .. attribute:: linVelocityMax
968 Clamp the maximum linear velocity to prevent objects moving beyond a set speed.
974 Applies to dynamic and rigid body objects only.
978 A value of 0.0 disables this option (rather then setting it stationary).
980 .. attribute:: localInertia
982 the object's inertia vector in local coordinates. Read only.
984 :type: list [ix, iy, iz]
986 .. attribute:: parent
988 The object's parent object. (read-only).
990 :type: :class:`KX_GameObject` or None
992 .. attribute:: group_children
994 Returns the list of group members if the object is a group object, otherwise None is returned.
996 :type: :class:`CListValue` of :class:`KX_GameObject` or None
998 .. attribute:: group_parent
1000 Returns the group object that the object belongs to or None if the object is not part of a group.
1002 :type: :class:`KX_GameObject` or None
1004 .. attribute:: scene
1006 The object's scene. (read-only).
1008 :type: :class:`KX_Scene` or None
1010 .. attribute:: visible
1018 Game logic will still run for invisible objects.
1020 .. attribute:: color
1022 The object color of the object. [r, g, b, a]
1024 :type: :class:`mathutils.Vector`
1026 .. attribute:: occlusion
1028 occlusion capability flag.
1032 .. attribute:: position
1034 The object's position. [x, y, z] On write: local position, on read: world position
1036 .. deprecated:: use :data:`localPosition` and :data:`worldPosition`.
1038 :type: :class:`mathutils.Vector`
1040 .. attribute:: orientation
1042 The object's orientation. 3x3 Matrix. You can also write a Quaternion or Euler vector. On write: local orientation, on read: world orientation
1044 .. deprecated:: use :data:`localOrientation` and :data:`worldOrientation`.
1046 :type: :class:`mathutils.Matrix`
1048 .. attribute:: scaling
1050 The object's scaling factor. [sx, sy, sz] On write: local scaling, on read: world scaling
1052 .. deprecated:: use :data:`localScale` and :data:`worldScale`.
1054 :type: :class:`mathutils.Vector`
1056 .. attribute:: localOrientation
1058 The object's local orientation. 3x3 Matrix. You can also write a Quaternion or Euler vector.
1060 :type: :class:`mathutils.Matrix`
1062 .. attribute:: worldOrientation
1064 The object's world orientation. 3x3 Matrix.
1066 :type: :class:`mathutils.Matrix`
1068 .. attribute:: localScale
1070 The object's local scaling factor. [sx, sy, sz]
1072 :type: :class:`mathutils.Vector`
1074 .. attribute:: worldScale
1076 The object's world scaling factor. [sx, sy, sz]
1078 :type: :class:`mathutils.Vector`
1080 .. attribute:: localPosition
1082 The object's local position. [x, y, z]
1084 :type: :class:`mathutils.Vector`
1086 .. attribute:: worldPosition
1088 The object's world position. [x, y, z]
1090 :type: :class:`mathutils.Vector`
1092 .. attribute:: localTransform
1094 The object's local space transform matrix. 4x4 Matrix.
1096 :type: :class:`mathutils.Matrix`
1098 .. attribute:: worldTransform
1100 The object's world space transform matrix. 4x4 Matrix.
1102 :type: :class:`mathutils.Matrix`
1104 .. attribute:: localLinearVelocity
1106 The object's local linear velocity. [x, y, z]
1108 :type: :class:`mathutils.Vector`
1110 .. attribute:: worldLinearVelocity
1112 The object's world linear velocity. [x, y, z]
1114 :type: :class:`mathutils.Vector`
1116 .. attribute:: localAngularVelocity
1118 The object's local angular velocity. [x, y, z]
1120 :type: :class:`mathutils.Vector`
1122 .. attribute:: worldAngularVelocity
1124 The object's world angular velocity. [x, y, z]
1126 :type: :class:`mathutils.Vector`
1128 .. attribute:: timeOffset
1130 adjust the slowparent delay at runtime.
1134 .. attribute:: state
1136 the game object's state bitmask, using the first 30 bits, one bit must always be set.
1140 .. attribute:: meshes
1142 a list meshes for this object.
1144 :type: list of :class:`KX_MeshProxy`
1148 Most objects use only 1 mesh.
1152 Changes to this list will not update the KX_GameObject.
1154 .. attribute:: sensors
1156 a sequence of :class:`SCA_ISensor` objects with string/index lookups and iterator support.
1162 This attribute is experemental and may be removed (but probably wont be).
1166 Changes to this list will not update the KX_GameObject.
1168 .. attribute:: controllers
1170 a sequence of :class:`SCA_IController` objects with string/index lookups and iterator support.
1172 :type: list of :class:`SCA_ISensor`
1176 This attribute is experemental and may be removed (but probably wont be).
1180 Changes to this list will not update the KX_GameObject.
1182 .. attribute:: actuators
1184 a list of :class:`SCA_IActuator` with string/index lookups and iterator support.
1190 This attribute is experemental and may be removed (but probably wont be).
1194 Changes to this list will not update the KX_GameObject.
1196 .. attribute:: attrDict
1198 get the objects internal python attribute dictionary for direct (faster) access.
1202 .. attribute:: children
1204 direct children of this object, (read-only).
1206 :type: :class:`CListValue` of :class:`KX_GameObject`'s
1208 .. attribute:: childrenRecursive
1210 all children of this object including childrens children, (read-only).
1212 :type: :class:`CListValue` of :class:`KX_GameObject`'s
1214 .. method:: endObject()
1216 Delete this object, can be used in place of the EndObject Actuator.
1218 The actual removal of the object from the scene is delayed.
1220 .. method:: replaceMesh(mesh, useDisplayMesh=True, usePhysicsMesh=False)
1222 Replace the mesh of this object with a new mesh. This works the same was as the actuator.
1224 :arg mesh: mesh to replace or the meshes name.
1225 :type mesh: :class:`MeshProxy` or string
1226 :arg useDisplayMesh: when enabled the display mesh will be replaced (optional argument).
1227 :type useDisplayMesh: boolean
1228 :arg usePhysicsMesh: when enabled the physics mesh will be replaced (optional argument).
1229 :type usePhysicsMesh: boolean
1231 .. method:: setVisible(visible, recursive)
1233 Sets the game object's visible flag.
1235 :arg visible: the visible state to set.
1236 :type visible: boolean
1237 :arg recursive: optional argument to set all childrens visibility flag too.
1238 :type recursive: boolean
1240 .. method:: setOcclusion(occlusion, recursive)
1242 Sets the game object's occlusion capability.
1244 :arg occlusion: the state to set the occlusion to.
1245 :type occlusion: boolean
1246 :arg recursive: optional argument to set all childrens occlusion flag too.
1247 :type recursive: boolean
1249 .. method:: alignAxisToVect(vect, axis=2, factor=1.0)
1251 Aligns any of the game object's axis along the given vector.
1254 :arg vect: a vector to align the axis.
1255 :type vect: 3D vector
1256 :arg axis: The axis you want to align
1263 :arg factor: Only rotate a feaction of the distance to the target vector (0.0 - 1.0)
1266 .. method:: getAxisVect(vect)
1268 Returns the axis vector rotates by the objects worldspace orientation.
1269 This is the equivalent of multiplying the vector by the orientation matrix.
1271 :arg vect: a vector to align the axis.
1272 :type vect: 3D Vector
1273 :return: The vector in relation to the objects rotation.
1276 .. method:: applyMovement(movement, local=False)
1278 Sets the game object's movement.
1280 :arg movement: movement vector.
1281 :type movement: 3D Vector
1283 * False: you get the "global" movement ie: relative to world orientation.
1284 * True: you get the "local" movement ie: relative to object orientation.
1287 .. method:: applyRotation(rotation, local=False)
1289 Sets the game object's rotation.
1291 :arg rotation: rotation vector.
1292 :type rotation: 3D Vector
1294 * False: you get the "global" rotation ie: relative to world orientation.
1295 * True: you get the "local" rotation ie: relative to object orientation.
1298 .. method:: applyForce(force, local=False)
1300 Sets the game object's force.
1302 This requires a dynamic object.
1304 :arg force: force vector.
1305 :type force: 3D Vector
1307 * False: you get the "global" force ie: relative to world orientation.
1308 * True: you get the "local" force ie: relative to object orientation.
1309 :type local: boolean
1311 .. method:: applyTorque(torque, local=False)
1313 Sets the game object's torque.
1315 This requires a dynamic object.
1317 :arg torque: torque vector.
1318 :type torque: 3D Vector
1320 * False: you get the "global" torque ie: relative to world orientation.
1321 * True: you get the "local" torque ie: relative to object orientation.
1322 :type local: boolean
1324 .. method:: getLinearVelocity(local=False)
1326 Gets the game object's linear velocity.
1328 This method returns the game object's velocity through it's centre of mass, ie no angular velocity component.
1331 * False: you get the "global" velocity ie: relative to world orientation.
1332 * True: you get the "local" velocity ie: relative to object orientation.
1333 :type local: boolean
1334 :return: the object's linear velocity.
1335 :rtype: list [vx, vy, vz]
1337 .. method:: setLinearVelocity(velocity, local=False)
1339 Sets the game object's linear velocity.
1341 This method sets game object's velocity through it's centre of mass,
1342 ie no angular velocity component.
1344 This requires a dynamic object.
1346 :arg velocity: linear velocity vector.
1347 :type velocity: 3D Vector
1349 * False: you get the "global" velocity ie: relative to world orientation.
1350 * True: you get the "local" velocity ie: relative to object orientation.
1351 :type local: boolean
1353 .. method:: getAngularVelocity(local=False)
1355 Gets the game object's angular velocity.
1358 * False: you get the "global" velocity ie: relative to world orientation.
1359 * True: you get the "local" velocity ie: relative to object orientation.
1360 :type local: boolean
1361 :return: the object's angular velocity.
1362 :rtype: list [vx, vy, vz]
1364 .. method:: setAngularVelocity(velocity, local=False)
1366 Sets the game object's angular velocity.
1368 This requires a dynamic object.
1370 :arg velocity: angular velocity vector.
1371 :type velocity: boolean
1373 * False: you get the "global" velocity ie: relative to world orientation.
1374 * True: you get the "local" velocity ie: relative to object orientation.
1376 .. method:: getVelocity(point=(0, 0, 0))
1378 Gets the game object's velocity at the specified point.
1380 Gets the game object's velocity at the specified point, including angular
1383 :arg point: optional point to return the velocity for, in local coordinates.
1384 :type point: 3D Vector
1385 :return: the velocity at the specified point.
1386 :rtype: list [vx, vy, vz]
1388 .. method:: getReactionForce()
1390 Gets the game object's reaction force.
1392 The reaction force is the force applied to this object over the last simulation timestep.
1393 This also includes impulses, eg from collisions.
1395 :return: the reaction force of this object.
1396 :rtype: list [fx, fy, fz]
1400 This is not implimented at the moment.
1402 .. method:: applyImpulse(point, impulse)
1404 Applies an impulse to the game object.
1406 This will apply the specified impulse to the game object at the specified point.
1407 If point != position, applyImpulse will also change the object's angular momentum.
1408 Otherwise, only linear momentum will change.
1410 :arg point: the point to apply the impulse to (in world coordinates)
1411 :type point: the point to apply the impulse to (in world coordinates)
1413 .. method:: suspendDynamics()
1415 Suspends physics for this object.
1417 .. method:: restoreDynamics()
1419 Resumes physics for this object.
1423 The objects linear velocity will be applied from when the dynamics were suspended.
1425 .. method:: enableRigidBody()
1427 Enables rigid body physics for this object.
1429 Rigid body physics allows the object to roll on collisions.
1431 .. method:: disableRigidBody()
1433 Disables rigid body physics for this object.
1435 .. method:: setParent(parent, compound=True, ghost=True)
1437 Sets this object's parent.
1438 Control the shape status with the optional compound and ghost parameters:
1440 In that case you can control if it should be ghost or not:
1442 :arg parent: new parent object.
1443 :type parent: :class:`KX_GameObject`
1444 :arg compound: whether the shape should be added to the parent compound shape.
1446 * True: the object shape should be added to the parent compound shape.
1447 * False: the object should keep its individual shape.
1449 :type compound: boolean
1450 :arg ghost: whether the object should be ghost while parented.
1452 * True: if the object should be made ghost while parented.
1453 * False: if the object should be solid while parented.
1455 :type ghost: boolean
1459 If the object type is sensor, it stays ghost regardless of ghost parameter
1461 .. method:: removeParent()
1463 Removes this objects parent.
1465 .. method:: getPhysicsId()
1467 Returns the user data object associated with this game object's physics controller.
1469 .. method:: getPropertyNames()
1471 Gets a list of all property names.
1473 :return: All property names for this object.
1476 .. method:: getDistanceTo(other)
1478 :arg other: a point or another :class:`KX_GameObject` to measure the distance to.
1479 :type other: :class:`KX_GameObject` or list [x, y, z]
1480 :return: distance to another object or point.
1483 .. method:: getVectTo(other)
1485 Returns the vector and the distance to another object or point.
1486 The vector is normalized unless the distance is 0, in which a zero length vector is returned.
1488 :arg other: a point or another :class:`KX_GameObject` to get the vector and distance to.
1489 :type other: :class:`KX_GameObject` or list [x, y, z]
1490 :return: (distance, globalVector(3), localVector(3))
1491 :rtype: 3-tuple (float, 3-tuple (x, y, z), 3-tuple (x, y, z))
1493 .. method:: rayCastTo(other, dist, prop)
1495 Look towards another point/object and find first object hit within dist that matches prop.
1497 The ray is always casted from the center of the object, ignoring the object itself.
1498 The ray is casted towards the center of another object or an explicit [x, y, z] point.
1499 Use rayCast() if you need to retrieve the hit point
1501 :arg other: [x, y, z] or object towards which the ray is casted
1502 :type other: :class:`KX_GameObject` or 3-tuple
1503 :arg dist: max distance to look (can be negative => look behind); 0 or omitted => detect up to other
1505 :arg prop: property name that object must have; can be omitted => detect any object
1507 :return: the first object hit or None if no object or object does not match prop
1508 :rtype: :class:`KX_GameObject`
1510 .. method:: rayCast(objto, objfrom, dist, prop, face, xray, poly)
1512 Look from a point/object to another point/object and find first object hit within dist that matches prop.
1513 if poly is 0, returns a 3-tuple with object reference, hit point and hit normal or (None, None, None) if no hit.
1514 if poly is 1, returns a 4-tuple with in addition a :class:`KX_PolyProxy` as 4th element.
1515 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.
1517 .. code-block:: python
1519 # shoot along the axis gun-gunAim (gunAim should be collision-free)
1520 obj, point, normal = gun.rayCast(gunAim, None, 50)
1525 The face paremeter determines the orientation of the normal.
1527 * 0 => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1528 * 1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
1530 The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
1531 The prop and xray parameters interact as follow.
1533 * prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
1534 * prop off, xray on : idem.
1535 * prop on, xray off: return closest hit if it matches prop, no hit otherwise.
1536 * 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.
1538 The :class:`KX_PolyProxy` 4th element of the return tuple when poly=1 allows to retrieve information on the polygon hit by the ray.
1539 If there is no hit or the hit object is not a static mesh, None is returned as 4th element.
1541 The ray ignores collision-free objects and faces that dont have the collision flag enabled, you can however use ghost objects.
1543 :arg objto: [x, y, z] or object to which the ray is casted
1544 :type objto: :class:`KX_GameObject` or 3-tuple
1545 :arg objfrom: [x, y, z] or object from which the ray is casted; None or omitted => use self object center
1546 :type objfrom: :class:`KX_GameObject` or 3-tuple or None
1547 :arg dist: max distance to look (can be negative => look behind); 0 or omitted => detect up to to
1549 :arg prop: property name that object must have; can be omitted or "" => detect any object
1551 :arg face: normal option: 1=>return face normal; 0 or omitted => normal is oriented towards origin
1553 :arg xray: X-ray option: 1=>skip objects that don't match prop; 0 or omitted => stop on first object
1555 :arg poly: polygon option: 0, 1 or 2 to return a 3-, 4- or 5-tuple with information on the face hit.
1557 * 0 or omitted: return value is a 3-tuple (object, hitpoint, hitnormal) or (None, None, None) if no hit
1558 * 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.
1559 * 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.
1562 :return: (object, hitpoint, hitnormal) or (object, hitpoint, hitnormal, polygon) or (object, hitpoint, hitnormal, polygon, hituv).
1564 * object, hitpoint and hitnormal are None if no hit.
1565 * 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
1566 * hituv is valid only if polygon is valid and the object has a UV mapping, otherwise it is None
1570 * 3-tuple (:class:`KX_GameObject`, 3-tuple (x, y, z), 3-tuple (nx, ny, nz))
1571 * or 4-tuple (:class:`KX_GameObject`, 3-tuple (x, y, z), 3-tuple (nx, ny, nz), :class:`PolyProxy`)
1572 * or 5-tuple (:class:`KX_GameObject`, 3-tuple (x, y, z), 3-tuple (nx, ny, nz), :class:`PolyProxy`, 2-tuple (u, v))
1576 The ray ignores the object on which the method is called. It is casted from/to object center or explicit [x, y, z] points.
1578 .. method:: setCollisionMargin(margin)
1580 Set the objects collision margin.
1582 :arg margin: the collision margin distance in blender units.
1587 If this object has no physics controller (a physics ID of zero), this function will raise RuntimeError.
1589 .. method:: sendMessage(subject, body="", to="")
1593 :arg subject: The subject of the message
1594 :type subject: string
1595 :arg body: The body of the message (optional)
1597 :arg to: The name of the object to send the message to (optional)
1600 .. method:: reinstancePhysicsMesh(gameObject, meshObject)
1602 Updates the physics system with the changed mesh.
1604 If no arguments are given the physics mesh will be re-created from the first mesh assigned to the game object.
1606 :arg gameObject: optional argument, set the physics shape from this gameObjets mesh.
1607 :type gameObject: string, :class:`KX_GameObject` or None
1608 :arg meshObject: optional argument, set the physics shape from this mesh.
1609 :type meshObject: string, :class:`MeshProxy` or None
1611 :return: True if reinstance succeeded, False if it failed.
1616 If this object has instances the other instances will be updated too.
1620 The gameObject argument has an advantage that it can convert from a mesh with modifiers applied (such as subsurf).
1624 Only triangle mesh type objects are supported currently (not convex hull)
1628 If the object is a part of a combound object it will fail (parent or child)
1632 Rebuilding the physics mesh can be slow, running many times per second will give a performance hit.
1634 .. method:: get(key, default=None)
1636 Return the value matching key, or the default value if its not found.
1637 :return: The key value or a default.
1639 .. 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)
1643 :arg name: the name of the action
1645 :arg start: the start frame of the action
1647 :arg end: the end frame of the action
1649 :arg layer: the layer the action will play in (actions in different layers are added/blended together)
1650 :type layer: integer
1651 :arg priority: only play this action if there isn't an action currently playing in this layer with a higher (lower number) priority
1652 :type priority: integer
1653 :arg blendin: the amount of blending between this animation and the previous one on this layer
1654 :type blendin: float
1655 :arg play_mode: the play mode
1656 :type play_mode: KX_ACTION_MODE_PLAY, KX_ACTION_MODE_LOOP, or KX_ACTION_MODE_PING_PONG
1657 :arg layer_weight: how much of the previous layer to use for blending (0 = add)
1658 :type layer_weight: float
1659 :arg ipo_flags: flags for the old IPO behaviors (force, etc)
1660 :type ipo_flags: int bitfield
1661 :arg speed: the playback speed of the action as a factor (1.0 = normal speed, 2.0 = 2x speed, etc)
1664 .. method:: stopAction(layer=0)
1666 Stop playing the action on the given layer.
1668 :arg layer: The layer to stop playing.
1669 :type layer: integer
1671 .. method:: getActionFrame(layer=0)
1673 Gets the current frame of the action playing in the supplied layer.
1675 :arg layer: The layer that you want to get the frame from.
1676 :type layer: integer
1678 :return: The current frame of the action
1681 .. method:: setActionFrame(frame, layer=0)
1683 Set the current frame of the action playing in the supplied layer.
1685 :arg layer: The layer where you want to set the frame
1686 :type layer: integer
1687 :arg frame: The frame to set the action to
1690 .. method:: isPlayingAction(layer=0)
1692 Checks to see if there is an action playing in the given layer.
1694 :arg layer: The layer to check for a playing action.
1695 :type layer: integer
1697 :return: Whether or not the action is playing
1700 .. class:: KX_IpoActuator(SCA_IActuator)
1702 IPO actuator activates an animation.
1704 .. attribute:: frameStart
1710 .. attribute:: frameEnd
1716 .. attribute:: propName
1718 Use this property to define the Ipo position.
1722 .. attribute:: framePropName
1724 Assign this property this action current frame number.
1730 Play mode for the ipo. Can be on of :ref:`these constants <ipo-actuator>`
1734 .. attribute:: useIpoAsForce
1736 Apply Ipo as a global or local force depending on the local option (dynamic objects only).
1740 .. attribute:: useIpoAdd
1742 Ipo is added to the current loc/rot/scale in global or local coordinate according to Local flag.
1746 .. attribute:: useIpoLocal
1748 Let the ipo acts in local coordinates, used in Force and Add mode.
1752 .. attribute:: useChildren
1754 Update IPO on all children Objects as well.
1758 .. class:: KX_LightObject(KX_GameObject)
1762 .. code-block:: python
1764 # Turn on a red alert light.
1767 co = bge.logic.getCurrentController()
1771 light.color = [1.0, 0.0, 0.0]
1775 A spot light source. See attribute :data:`type`
1779 A point light source with no attenuation. See attribute :data:`type`
1783 A point light source. See attribute :data:`type`
1787 The type of light - must be SPOT, SUN or NORMAL
1789 .. attribute:: layer
1791 The layer mask that this light affects object on.
1795 .. attribute:: energy
1797 The brightness of this light.
1801 .. attribute:: distance
1803 The maximum distance this light can illuminate. (SPOT and NORMAL lights only).
1807 .. attribute:: color
1809 The color of this light. Black = [0.0, 0.0, 0.0], White = [1.0, 1.0, 1.0].
1811 :type: list [r, g, b]
1813 .. attribute:: colour
1817 .. attribute:: lin_attenuation
1819 The linear component of this light's attenuation. (SPOT and NORMAL lights only).
1823 .. attribute:: quad_attenuation
1825 The quadratic component of this light's attenuation (SPOT and NORMAL lights only).
1829 .. attribute:: spotsize
1831 The cone angle of the spot light, in degrees (SPOT lights only).
1833 :type: float in [0 - 180].
1835 .. attribute:: spotblend
1837 Specifies the intensity distribution of the spot light (SPOT lights only).
1839 :type: float in [0 - 1]
1843 Higher values result in a more focused light source.
1845 .. class:: KX_MeshProxy(SCA_IObject)
1849 You can only change the vertex properties of a mesh object, not the mesh topology.
1851 To use mesh objects effectively, you should know a bit about how the game engine handles them.
1853 #. Mesh Objects are converted from Blender at scene load.
1854 #. The Converter groups polygons by Material. This means they can be sent to the renderer efficiently. A material holds:
1857 #. The Blender material.
1858 #. The Tile properties
1859 #. The face properties - (From the "Texture Face" panel)
1860 #. Transparency & z sorting
1862 #. Polygon shape (triangle/quad)
1865 #. Vertices will be split by face if necessary. Vertices can only be shared between faces if:
1867 #. They are at the same position
1868 #. UV coordinates are the same
1869 #. Their normals are the same (both polygons are "Set Smooth")
1870 #. They are the same color, for example: a cube has 24 vertices: 6 faces with 4 vertices per face.
1872 The correct method of iterating over every :class:`KX_VertexProxy` in a game object
1874 .. code-block:: python
1876 from bge import logic
1878 cont = logic.getCurrentController()
1881 for mesh in object.meshes:
1882 for m_index in range(len(mesh.materials)):
1883 for v_index in range(mesh.getVertexArrayLength(m_index)):
1884 vertex = mesh.getVertex(m_index, v_index)
1885 # Do something with vertex here...
1886 # ... eg: color the vertex red.
1887 vertex.color = [1.0, 0.0, 0.0, 1.0]
1889 .. attribute:: materials
1891 :type: list of :class:`KX_BlenderMaterial` or :class:`KX_PolygonMaterial` types
1893 .. attribute:: numPolygons
1897 .. attribute:: numMaterials
1901 .. method:: getNumMaterials()
1903 :return: number of materials associated with this object
1906 .. method:: getMaterialName(matid)
1908 Gets the name of the specified material.
1910 :arg matid: the specified material.
1911 :type matid: integer
1912 :return: the attached material name.
1915 .. method:: getTextureName(matid)
1917 Gets the name of the specified material's texture.
1919 :arg matid: the specified material
1920 :type matid: integer
1921 :return: the attached material's texture name.
1924 .. method:: getVertexArrayLength(matid)
1926 Gets the length of the vertex array associated with the specified material.
1928 There is one vertex array for each material.
1930 :arg matid: the specified material
1931 :type matid: integer
1932 :return: the number of verticies in the vertex array.
1935 .. method:: getVertex(matid, index)
1937 Gets the specified vertex from the mesh object.
1939 :arg matid: the specified material
1940 :type matid: integer
1941 :arg index: the index into the vertex array.
1942 :type index: integer
1943 :return: a vertex object.
1944 :rtype: :class:`KX_VertexProxy`
1946 .. method:: getNumPolygons()
1948 :return: The number of polygon in the mesh.
1951 .. method:: getPolygon(index)
1953 Gets the specified polygon from the mesh.
1955 :arg index: polygon number
1956 :type index: integer
1957 :return: a polygon object.
1958 :rtype: :class:`PolyProxy`
1960 .. class:: SCA_MouseSensor(SCA_ISensor)
1962 Mouse Sensor logic brick.
1964 .. attribute:: position
1966 current [x, y] coordinates of the mouse, in frame coordinates (pixels).
1968 :type: [integer, interger]
1976 * KX_MOUSESENSORMODE_LEFTBUTTON(1)
1977 * KX_MOUSESENSORMODE_MIDDLEBUTTON(2)
1978 * KX_MOUSESENSORMODE_RIGHTBUTTON(3)
1979 * KX_MOUSESENSORMODE_WHEELUP(4)
1980 * KX_MOUSESENSORMODE_WHEELDOWN(5)
1981 * KX_MOUSESENSORMODE_MOVEMENT(6)
1983 .. method:: getButtonStatus(button)
1985 Get the mouse button status.
1987 :arg button: The code that represents the key you want to get the state of, use one of :ref:`these constants<mouse-keys>`
1989 :return: The state of the given key, can be one of :ref:`these constants<input-status>`
1992 .. class:: KX_MouseFocusSensor(SCA_MouseSensor)
1994 The mouse focus sensor detects when the mouse is over the current game object.
1996 The mouse focus sensor works by transforming the mouse coordinates from 2d device
1997 space to 3d space then raycasting away from the camera.
1999 .. attribute:: raySource
2001 The worldspace source of the ray (the view position).
2003 :type: list (vector of 3 floats)
2005 .. attribute:: rayTarget
2007 The worldspace target of the ray.
2009 :type: list (vector of 3 floats)
2011 .. attribute:: rayDirection
2013 The :data:`rayTarget` - :class:`raySource` normalized.
2015 :type: list (normalized vector of 3 floats)
2017 .. attribute:: hitObject
2019 the last object the mouse was over.
2021 :type: :class:`KX_GameObject` or None
2023 .. attribute:: hitPosition
2025 The worldspace position of the ray intersecton.
2027 :type: list (vector of 3 floats)
2029 .. attribute:: hitNormal
2031 the worldspace normal from the face at point of intersection.
2033 :type: list (normalized vector of 3 floats)
2035 .. attribute:: hitUV
2037 the UV coordinates at the point of intersection.
2039 :type: list (vector of 2 floats)
2041 If the object has no UV mapping, it returns [0, 0].
2043 The UV coordinates are not normalized, they can be < 0 or > 1 depending on the UV mapping.
2045 .. attribute:: usePulseFocus
2047 When enabled, moving the mouse over a different object generates a pulse. (only used when the 'Mouse Over Any' sensor option is set).
2051 .. class:: KX_TouchSensor(SCA_ISensor)
2053 Touch sensor detects collisions between objects.
2055 .. attribute:: propName
2057 The property or material to collide with.
2061 .. attribute:: useMaterial
2063 Determines if the sensor is looking for a property or material. KX_True = Find material; KX_False = Find property.
2067 .. attribute:: usePulseCollision
2069 When enabled, changes to the set of colliding objects generate a pulse.
2073 .. attribute:: hitObject
2075 The last collided object. (read-only).
2077 :type: :class:`KX_GameObject` or None
2079 .. attribute:: hitObjectList
2081 A list of colliding objects. (read-only).
2083 :type: :class:`CListValue` of :class:`KX_GameObject`
2085 .. class:: KX_NearSensor(KX_TouchSensor)
2087 A near sensor is a specialised form of touch sensor.
2089 .. attribute:: distance
2091 The near sensor activates when an object is within this distance.
2095 .. attribute:: resetDistance
2097 The near sensor deactivates when the object exceeds this distance.
2101 .. class:: KX_NetworkMessageActuator(SCA_IActuator)
2105 .. attribute:: propName
2107 Messages will only be sent to objects with the given property name.
2111 .. attribute:: subject
2113 The subject field of the message.
2119 The body of the message.
2123 .. attribute:: usePropBody
2125 Send a property instead of a regular body message.
2129 .. class:: KX_NetworkMessageSensor(SCA_ISensor)
2131 The Message Sensor logic brick.
2133 Currently only loopback (local) networks are supported.
2135 .. attribute:: subject
2137 The subject the sensor is looking for.
2141 .. attribute:: frameMessageCount
2143 The number of messages received since the last frame. (read-only).
2147 .. attribute:: subjects
2149 The list of message subjects received. (read-only).
2151 :type: list of strings
2153 .. attribute:: bodies
2155 The list of message bodies received. (read-only).
2157 :type: list of strings
2159 .. class:: KX_ObjectActuator(SCA_IActuator)
2161 The object actuator ("Motion Actuator") applies force, torque, displacement, angular displacement,
2162 velocity, or angular velocity to an object.
2163 Servo control allows to regulate force to achieve a certain speed target.
2165 .. attribute:: force
2167 The force applied by the actuator.
2169 :type: list [x, y, z]
2171 .. attribute:: useLocalForce
2173 A flag specifying if the force is local.
2177 .. attribute:: torque
2179 The torque applied by the actuator.
2181 :type: list [x, y, z]
2183 .. attribute:: useLocalTorque
2185 A flag specifying if the torque is local.
2191 The displacement vector applied by the actuator.
2193 :type: list [x, y, z]
2195 .. attribute:: useLocalDLoc
2197 A flag specifying if the dLoc is local.
2203 The angular displacement vector applied by the actuator
2205 :type: list [x, y, z]
2209 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.
2211 .. attribute:: useLocalDRot
2213 A flag specifying if the dRot is local.
2219 The linear velocity applied by the actuator.
2221 :type: list [x, y, z]
2223 .. attribute:: useLocalLinV
2225 A flag specifying if the linear velocity is local.
2231 This is the target speed for servo controllers.
2235 The angular velocity applied by the actuator.
2237 :type: list [x, y, z]
2239 .. attribute:: useLocalAngV
2241 A flag specifying if the angular velocity is local.
2245 .. attribute:: damping
2247 The damping parameter of the servo controller.
2251 .. attribute:: forceLimitX
2253 The min/max force limit along the X axis and activates or deactivates the limits in the servo controller.
2255 :type: list [min(float), max(float), bool]
2257 .. attribute:: forceLimitY
2259 The min/max force limit along the Y axis and activates or deactivates the limits in the servo controller.
2261 :type: list [min(float), max(float), bool]
2263 .. attribute:: forceLimitZ
2265 The min/max force limit along the Z axis and activates or deactivates the limits in the servo controller.
2267 :type: list [min(float), max(float), bool]
2271 The PID coefficients of the servo controller.
2273 :type: list of floats [proportional, integral, derivate]
2275 .. attribute:: reference
2277 The object that is used as reference to compute the velocity for the servo controller.
2279 :type: :class:`KX_GameObject` or None
2281 .. class:: KX_ParentActuator(SCA_IActuator)
2283 The parent actuator can set or remove an objects parent object.
2285 .. attribute:: object
2287 the object this actuator sets the parent too.
2289 :type: :class:`KX_GameObject` or None
2293 The mode of this actuator.
2295 :type: integer from 0 to 1.
2297 .. attribute:: compound
2299 Whether the object shape should be added to the parent compound shape when parenting.
2301 Effective only if the parent is already a compound shape.
2305 .. attribute:: ghost
2307 Whether the object should be made ghost when parenting
2308 Effective only if the shape is not added to the parent compound shape.
2312 .. class:: KX_PhysicsObjectWrapper(PyObjectPlus)
2314 KX_PhysicsObjectWrapper
2316 .. method:: setActive(active)
2318 Set the object to be active.
2320 :arg active: set to True to be active
2321 :type active: boolean
2323 .. method:: setAngularVelocity(x, y, z, local)
2325 Set the angular velocity of the object.
2327 :arg x: angular velocity for the x-axis
2330 :arg y: angular velocity for the y-axis
2333 :arg z: angular velocity for the z-axis
2336 :arg local: set to True for local axis
2337 :type local: boolean
2339 .. method:: setLinearVelocity(x, y, z, local)
2341 Set the linear velocity of the object.
2343 :arg x: linear velocity for the x-axis
2346 :arg y: linear velocity for the y-axis
2349 :arg z: linear velocity for the z-axis
2352 :arg local: set to True for local axis
2353 :type local: boolean
2355 .. class:: KX_PolyProxy(SCA_IObject)
2357 A polygon holds the index of the vertex forming the poylgon.
2360 The polygon attributes are read-only, you need to retrieve the vertex proxy if you want
2361 to change the vertex settings.
2363 .. attribute:: matname
2365 The name of polygon material, empty if no material.
2369 .. attribute:: material
2371 The material of the polygon.
2373 :type: :class:`KX_PolygonMaterial` or :class:`KX_BlenderMaterial`
2375 .. attribute:: texture
2377 The texture name of the polygon.
2381 .. attribute:: matid
2383 The material index of the polygon, use this to retrieve vertex proxy from mesh proxy.
2389 vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy.
2395 vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy.
2401 vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy.
2407 Vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
2408 Use this to retrieve vertex proxy from mesh proxy.
2412 .. attribute:: visible
2414 visible state of the polygon: 1=visible, 0=invisible.
2418 .. attribute:: collide
2420 collide state of the polygon: 1=receives collision, 0=collision free.
2424 .. method:: getMaterialName()
2426 Returns the polygon material name with MA prefix
2428 :return: material name
2431 .. method:: getMaterial()
2433 :return: The polygon material
2434 :rtype: :class:`KX_PolygonMaterial` or :class:`KX_BlenderMaterial`
2436 .. method:: getTextureName()
2438 :return: The texture name
2441 .. method:: getMaterialIndex()
2443 Returns the material bucket index of the polygon.
2444 This index and the ones returned by getVertexIndex() are needed to retrieve the vertex proxy from :class:`MeshProxy`.
2446 :return: the material index in the mesh
2449 .. method:: getNumVertex()
2451 Returns the number of vertex of the polygon.
2453 :return: number of vertex, 3 or 4.
2456 .. method:: isVisible()
2458 Returns whether the polygon is visible or not
2460 :return: 0=invisible, 1=visible
2463 .. method:: isCollider()
2465 Returns whether the polygon is receives collision or not
2467 :return: 0=collision free, 1=receives collision
2470 .. method:: getVertexIndex(vertex)
2472 Returns the mesh vertex index of a polygon vertex
2473 This index and the one returned by getMaterialIndex() are needed to retrieve the vertex proxy from :class:`MeshProxy`.
2475 :arg vertex: index of the vertex in the polygon: 0->3
2476 :arg vertex: integer
2477 :return: mesh vertex index
2480 .. method:: getMesh()
2482 Returns a mesh proxy
2485 :rtype: :class:`MeshProxy`
2487 .. class:: KX_PolygonMaterial(PyObjectPlus)
2489 This is the interface to materials in the game engine.
2491 Materials define the render state to be applied to mesh objects.
2495 Some of the methods/variables are CObjects. If you mix these up, you will crash blender.
2497 .. code-block:: python
2499 from bge import logic
2505 // original vertex position, no changes
2506 gl_Position = ftransform();
2507 // coordinate of the 1st texture channel
2508 gl_TexCoord[0] = gl_MultiTexCoord0;
2509 // coordinate of the 2nd texture channel
2510 gl_TexCoord[1] = gl_MultiTexCoord1;
2514 fragment_shader ="""
2516 uniform sampler2D color_0;
2517 uniform sampler2D color_1;
2518 uniform float factor;
2522 vec4 color_0 = texture2D(color_0, gl_TexCoord[0].st);
2523 vec4 color_1 = texture2D(color_1, gl_TexCoord[1].st);
2524 gl_FragColor = mix(color_0, color_1, factor);
2528 object = logic.getCurrentController().owner
2530 for mesh in object.meshes:
2531 for material in mesh.materials:
2532 shader = material.getShader()
2534 if not shader.isValid():
2535 shader.setSource(vertex_shader, fragment_shader, True)
2537 # get the first texture channel of the material
2538 shader.setSampler('color_0', 0)
2539 # get the second texture channel of the material
2540 shader.setSampler('color_1', 1)
2541 # pass another uniform to the shader
2542 shader.setUniform1f('factor', 0.3)
2545 .. attribute:: texture
2549 :type: string (read-only)
2551 .. attribute:: gl_texture
2553 OpenGL texture handle (eg for glBindTexture(GL_TEXTURE_2D, gl_texture).
2555 :type: integer (read-only)
2557 .. attribute:: material
2561 :type: string (read-only)
2563 .. attribute:: tface
2565 Texture face properties.
2567 :type: CObject (read-only)
2575 .. attribute:: tilexrep
2577 Number of tile repetitions in x direction.
2581 .. attribute:: tileyrep
2583 Number of tile repetitions in y direction.
2587 .. attribute:: drawingmode
2589 Drawing mode for the material.
2590 - 2 (drawingmode & 4) Textured
2591 - 4 (drawingmode & 16) Light
2592 - 14 (drawingmode & 16384) 3d Polygon Text.
2596 .. attribute:: transparent
2598 This material is transparent. All meshes with this
2599 material will be rendered after non transparent meshes from back
2604 .. attribute:: zsort
2606 Transparent polygons in meshes with this material will be sorted back to
2607 front before rendering.
2608 Non-Transparent polygons will be sorted front to back before rendering.
2612 .. attribute:: lightlayer
2614 Light layers this material affects.
2618 .. attribute:: triangle
2620 Mesh data with this material is triangles. It's probably not safe to change this.
2624 .. attribute:: diffuse
2626 The diffuse color of the material. black = [0.0, 0.0, 0.0] white = [1.0, 1.0, 1.0].
2628 :type: list [r, g, b]
2630 .. attribute:: specular
2632 The specular color of the material. black = [0.0, 0.0, 0.0] white = [1.0, 1.0, 1.0].
2634 :type: list [r, g, b]
2636 .. attribute:: shininess
2638 The shininess (specular exponent) of the material. 0.0 <= shininess <= 128.0.
2642 .. attribute:: specularity
2644 The amount of specular of the material. 0.0 <= specularity <= 1.0.
2648 .. method:: updateTexture(tface, rasty)
2650 Updates a realtime animation.
2652 :arg tface: Texture face (eg mat.tface)
2653 :type tface: CObject
2654 :arg rasty: Rasterizer
2655 :type rasty: CObject
2657 .. method:: setTexture(tface)
2659 Sets texture render state.
2661 :arg tface: Texture face
2662 :type tface: CObject
2664 .. code-block:: python
2666 mat.setTexture(mat.tface)
2668 .. method:: activate(rasty, cachingInfo)
2670 Sets material parameters for this object for rendering.
2672 Material Parameters set:
2682 :arg rasty: Rasterizer instance.
2683 :type rasty: CObject
2684 :arg cachingInfo: Material cache instance.
2685 :type cachingInfo: CObject
2687 .. method:: setCustomMaterial(material)
2689 Sets the material state setup object.
2691 Using this method, you can extend or completely replace the gameengine material
2692 to do your own advanced multipass effects.
2694 Use this method to register your material class. Instead of the normal material,
2695 your class's activate method will be called just before rendering the mesh.
2696 This should setup the texture, material, and any other state you would like.
2697 It should return True to render the mesh, or False if you are finished. You should
2698 clean up any state Blender does not set before returning False.
2700 Activate Method Definition:
2702 .. code-block:: python
2704 def activate(self, rasty, cachingInfo, material):
2706 :arg material: The material object.
2707 :type material: instance
2709 .. code-block:: python
2715 def activate(self, rasty, cachingInfo, material):
2716 # Activate the material here.
2718 # The activate method will be called until it returns False.
2719 # Every time the activate method returns True the mesh will
2722 # rasty is a CObject for passing to material.updateTexture()
2723 # and material.activate()
2724 # cachingInfo is a CObject for passing to material.activate()
2725 # material is the KX_PolygonMaterial instance this material
2728 # default material properties:
2730 if self.pass_no == 0:
2731 material.activate(rasty, cachingInfo)
2732 # Return True to do this pass
2735 # clean up and return False to finish.
2739 # Create a new Python Material and pass it to the renderer.
2740 mat.setCustomMaterial(PyMaterial())
2742 .. class:: KX_RadarSensor(KX_NearSensor)
2744 Radar sensor is a near sensor with a conical sensor object.
2746 .. attribute:: coneOrigin
2748 The origin of the cone with which to test. The origin is in the middle of the cone. (read-only).
2750 :type: list of floats [x, y, z]
2752 .. attribute:: coneTarget
2754 The center of the bottom face of the cone with which to test. (read-only).
2756 :type: list of floats [x, y, z]
2758 .. attribute:: distance
2760 The height of the cone with which to test.
2764 .. attribute:: angle
2766 The angle of the cone (in degrees) with which to test.
2772 The axis on which the radar cone is cast.
2774 :type: integer from 0 to 5
2776 KX_RADAR_AXIS_POS_X, KX_RADAR_AXIS_POS_Y, KX_RADAR_AXIS_POS_Z,
2777 KX_RADAR_AXIS_NEG_X, KX_RADAR_AXIS_NEG_Y, KX_RADAR_AXIS_NEG_Z
2779 .. class:: KX_RaySensor(SCA_ISensor)
2781 A ray sensor detects the first object in a given direction.
2783 .. attribute:: propName
2785 The property the ray is looking for.
2789 .. attribute:: range
2791 The distance of the ray.
2795 .. attribute:: useMaterial
2797 Whether or not to look for a material (false = property).
2801 .. attribute:: useXRay
2803 Whether or not to use XRay.
2807 .. attribute:: hitObject
2809 The game object that was hit by the ray. (read-only).
2811 :type: :class:`KX_GameObject`
2813 .. attribute:: hitPosition
2815 The position (in worldcoordinates) where the object was hit by the ray. (read-only).
2817 :type: list [x, y, z]
2819 .. attribute:: hitNormal
2821 The normal (in worldcoordinates) of the object at the location where the object was hit by the ray. (read-only).
2823 :type: list [x, y, z]
2825 .. attribute:: rayDirection
2827 The direction from the ray (in worldcoordinates). (read-only).
2829 :type: list [x, y, z]
2833 The axis the ray is pointing on.
2835 :type: integer from 0 to 5
2844 .. class:: KX_SCA_AddObjectActuator(SCA_IActuator)
2846 Edit Object Actuator (in Add Object Mode)
2850 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.
2852 .. code-block:: none
2854 Error: GameObject 'Name' has a AddObjectActuator 'ActuatorName' without object (in 'nonactive' layer)
2856 .. attribute:: object
2858 the object this actuator adds.
2860 :type: :class:`KX_GameObject` or None
2862 .. attribute:: objectLastCreated
2864 the last added object from this actuator (read-only).
2866 :type: :class:`KX_GameObject` or None
2870 the lifetime of added objects, in frames. Set to 0 to disable automatic deletion.
2874 .. attribute:: linearVelocity
2876 the initial linear velocity of added objects.
2878 :type: list [vx, vy, vz]
2880 .. attribute:: angularVelocity
2882 the initial angular velocity of added objects.
2884 :type: list [vx, vy, vz]
2886 .. method:: instantAddObject()
2888 adds the object without needing to calling SCA_PythonController.activate()
2890 .. note:: Use objectLastCreated to get the newly created object.
2892 .. class:: KX_SCA_DynamicActuator(SCA_IActuator)
2900 the type of operation of the actuator, 0-4
2902 * KX_DYN_RESTORE_DYNAMICS(0)
2903 * KX_DYN_DISABLE_DYNAMICS(1)
2904 * KX_DYN_ENABLE_RIGID_BODY(2)
2905 * KX_DYN_DISABLE_RIGID_BODY(3)
2906 * KX_DYN_SET_MASS(4)
2910 the mass value for the KX_DYN_SET_MASS operation.
2914 .. class:: KX_SCA_EndObjectActuator(SCA_IActuator)
2916 Edit Object Actuator (in End Object mode)
2918 This actuator has no python methods.
2920 .. class:: KX_SCA_ReplaceMeshActuator(SCA_IActuator)
2922 Edit Object actuator, in Replace Mesh mode.
2926 Replace mesh actuators will be ignored if at game start, the named mesh doesn't exist.
2928 This will generate a warning in the console
2930 .. code-block:: none
2932 Error: GameObject 'Name' ReplaceMeshActuator 'ActuatorName' without object
2934 .. code-block:: python
2937 # Switch a game object's mesh based on its depth in the camera view.
2938 # +----------+ +-----------+ +-------------------------------------+
2939 # | Always +-----+ Python +-----+ Edit Object (Replace Mesh) LOD.Mesh |
2940 # +----------+ +-----------+ +-------------------------------------+
2941 from bge import logic
2943 # List detail meshes here
2944 # Mesh (name, near, far)
2945 # Meshes overlap so that they don't 'pop' when on the edge of the distance.
2946 meshes = ((".Hi", 0.0, -20.0),
2947 (".Med", -15.0, -50.0),
2948 (".Lo", -40.0, -100.0)
2951 cont = logic.getCurrentController()
2953 actuator = cont.actuators["LOD." + obj.name]
2954 camera = logic.getCurrentScene().active_camera
2956 def Depth(pos, plane):
2957 return pos[0]*plane[0] + pos[1]*plane[1] + pos[2]*plane[2] + plane[3]
2959 # Depth is negative and decreasing further from the camera
2960 depth = Depth(object.position, camera.world_to_camera[2])
2964 # Find the lowest detail mesh for depth
2966 if depth < mesh[1] and depth > mesh[2]:
2968 if "ME" + object.name + mesh[0] == actuator.getMesh():
2971 if newmesh != None and "ME" + object.name + newmesh[0] != actuator.mesh:
2972 # The mesh is a different mesh - switch it.
2973 # Check the current mesh is not a better fit.
2974 if curmesh == None or curmesh[1] < depth or curmesh[2] > depth:
2975 actuator.mesh = object.name + newmesh[0]
2976 cont.activate(actuator)
2980 :class:`MeshProxy` or the name of the mesh that will replace the current one.
2982 Set to None to disable actuator.
2984 :type: :class:`MeshProxy` or None if no mesh is set
2986 .. attribute:: useDisplayMesh
2988 when true the displayed mesh is replaced.
2992 .. attribute:: usePhysicsMesh
2994 when true the physics mesh is replaced.
2998 .. method:: instantReplaceMesh()
3000 Immediately replace mesh without delay.
3002 .. class:: KX_Scene(PyObjectPlus)
3004 An active scene that gives access to objects, cameras, lights and scene attributes.
3006 The activity culling stuff is supposed to disable logic bricks when their owner gets too far
3007 from the active camera. It was taken from some code lurking at the back of KX_Scene - who knows
3010 .. code-block:: python
3012 from bge import logic
3015 scene = logic.getCurrentScene()
3017 # print all the objects in the scene
3018 for object in scene.objects:
3021 # get an object named 'Cube'
3022 object = scene.objects["Cube"]
3024 # get the first object in the scene.
3025 object = scene.objects[0]
3027 .. code-block:: python
3029 # Get the depth of an object in the camera view.
3030 from bge import logic
3032 object = logic.getCurrentController().owner
3033 cam = logic.getCurrentScene().active_camera
3035 # Depth is negative and decreasing further from the camera
3036 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]
3038 @bug: All attributes are read only at the moment.
3042 The scene's name, (read-only).
3046 .. attribute:: objects
3048 A list of objects in the scene, (read-only).
3050 :type: :class:`CListValue` of :class:`KX_GameObject`
3052 .. attribute:: objectsInactive
3054 A list of objects on background layers (used for the addObject actuator), (read-only).
3056 :type: :class:`CListValue` of :class:`KX_GameObject`
3058 .. attribute:: lights
3060 A list of lights in the scene, (read-only).
3062 :type: :class:`CListValue` of :class:`KX_LightObject`
3064 .. attribute:: cameras
3066 A list of cameras in the scene, (read-only).
3068 :type: :class:`CListValue` of :class:`KX_Camera`
3070 .. attribute:: active_camera
3072 The current active camera.
3074 :type: :class:`KX_Camera`
3078 This can be set directly from python to avoid using the :class:`KX_SceneActuator`.
3080 .. attribute:: suspended
3082 True if the scene is suspended, (read-only).
3086 .. attribute:: activity_culling
3088 True if the scene is activity culling.
3092 .. attribute:: activity_culling_radius
3094 The distance outside which to do activity culling. Measured in manhattan distance.
3098 .. attribute:: dbvt_culling
3100 True when Dynamic Bounding box Volume Tree is set (read-only).
3104 .. attribute:: pre_draw
3106 A list of callables to be run before the render step.
3110 .. attribute:: post_draw
3112 A list of callables to be run after the render step.
3116 .. attribute:: gravity
3118 The scene gravity using the world x, y and z axis.
3120 :type: list [fx, fy, fz]
3122 .. method:: addObject(object, other, time=0)
3124 Adds an object to the scene like the Add Object Actuator would.
3126 :arg object: The object to add
3127 :type object: :class:`KX_GameObject` or string
3128 :arg other: The object's center to use when adding the object
3129 :type other: :class:`KX_GameObject` or string
3130 :arg time: The lifetime of the added object, in frames. A time of 0 means the object will last forever.
3132 :return: The newly added object.
3133 :rtype: :class:`KX_GameObject`
3137 Removes the scene from the game.
3139 .. method:: restart()
3143 .. method:: replace(scene)
3145 Replaces this scene with another one.
3147 :arg scene: The name of the scene to replace this scene with.
3150 .. method:: suspend()
3152 Suspends this scene.
3154 .. method:: resume()
3158 .. method:: get(key, default=None)
3160 Return the value matching key, or the default value if its not found.
3161 :return: The key value or a default.
3163 .. class:: KX_SceneActuator(SCA_IActuator)
3165 Scene Actuator logic brick.
3169 Scene actuators that use a scene name will be ignored if at game start, the named scene doesn't exist or is empty
3171 This will generate a warning in the console:
3173 .. code-block:: none
3175 Error: GameObject 'Name' has a SceneActuator 'ActuatorName' (SetScene) without scene
3177 .. attribute:: scene
3179 the name of the scene to change to/overlay/underlay/remove/suspend/resume.
3183 .. attribute:: camera
3185 the camera to change to.
3187 :type: :class:`KX_Camera` on read, string or :class:`KX_Camera` on write
3191 When setting the attribute, you can use either a :class:`KX_Camera` or the name of the camera.
3193 .. attribute:: useRestart
3195 Set flag to True to restart the sene.
3201 The mode of the actuator.
3203 :type: integer from 0 to 5.
3205 .. class:: KX_SoundActuator(SCA_IActuator)
3209 The :data:`startSound`, :data:`pauseSound` and :data:`stopSound` do not requirethe actuator to be activated - they act instantly provided that the actuator has been activated once at least.
3211 .. attribute:: fileName
3213 The filename of the sound this actuator plays.
3217 .. attribute:: volume
3219 The volume (gain) of the sound.
3223 .. attribute:: pitch
3225 The pitch of the sound.
3229 .. attribute:: rollOffFactor
3231 The roll off factor. Rolloff defines the rate of attenuation as the sound gets further away.
3235 .. attribute:: looping
3237 The loop mode of the actuator.
3241 .. attribute:: position
3243 The position of the sound as a list: [x, y, z].
3247 .. attribute:: velocity
3249 The velocity of the emitter as a list: [x, y, z]. The relative velocity to the observer determines the pitch. List of 3 floats: [x, y, z].
3253 .. attribute:: orientation
3255 The orientation of the sound. When setting the orientation you can also use quaternion [float, float, float, float] or euler angles [float, float, float].
3257 :type: 3x3 matrix [[float]]
3261 The operation mode of the actuator. Can be one of :ref:`these constants<logic-sound-actuator>`
3265 .. class:: KX_StateActuator(SCA_IActuator)
3267 State actuator changes the state mask of parent object.
3269 .. attribute:: operation
3271 Type of bit operation to be applied on object state mask.
3273 You can use one of :ref:`these constants <state-actuator-operation>`
3279 Value that defines the bits that will be modified by the operation.
3281 The bits that are 1 in the mask will be updated in the object state.
3283 The bits that are 0 are will be left unmodified expect for the Copy operation which copies the mask to the object state.
3287 .. class:: KX_TrackToActuator(SCA_IActuator)
3289 Edit Object actuator in Track To mode.
3293 Track To Actuators will be ignored if at game start, the object to track to is invalid.
3295 This will generate a warning in the console:
3297 .. code-block:: none
3299 GameObject 'Name' no object in EditObjectActuator 'ActuatorName'
3301 .. attribute:: object
3303 the object this actuator tracks.
3305 :type: :class:`KX_GameObject` or None
3309 the time in frames with which to delay the tracking motion.
3313 .. attribute:: use3D
3315 the tracking motion to use 3D.
3319 .. class:: KX_VehicleWrapper(PyObjectPlus)
3325 .. method:: addWheel(wheel, attachPos, attachDir, axleDir, suspensionRestLength, wheelRadius, hasSteering)
3327 Add a wheel to the vehicle
3329 :arg wheel: The object to use as a wheel.
3330 :type wheel: :class:`KX_GameObject` or a KX_GameObject name
3331 :arg attachPos: The position that this wheel will attach to.
3332 :type attachPos: vector of 3 floats
3333 :arg attachDir: The direction this wheel points.
3334 :type attachDir: vector of 3 floats
3335 :arg axleDir: The direction of this wheels axle.
3336 :type axleDir: vector of 3 floats
3337 :arg suspensionRestLength: TODO - Description
3338 :type suspensionRestLength: float
3339 :arg wheelRadius: The size of the wheel.
3340 :type wheelRadius: float
3342 .. method:: applyBraking(force, wheelIndex)
3344 Apply a braking force to the specified wheel
3346 :arg force: the brake force
3349 :arg wheelIndex: index of the wheel where the force needs to be applied
3350 :type wheelIndex: integer
3352 .. method:: applyEngineForce(force, wheelIndex)
3354 Apply an engine force to the specified wheel
3356 :arg force: the engine force
3359 :arg wheelIndex: index of the wheel where the force needs to be applied
3360 :type wheelIndex: integer
3362 .. method:: getConstraintId()
3364 Get the constraint ID
3366 :return: the constraint id
3369 .. method:: getConstraintType()
3371 Returns the constraint type.
3373 :return: constraint type
3376 .. method:: getNumWheels()
3378 Returns the number of wheels.
3380 :return: the number of wheels for this vehicle
3383 .. method:: getWheelOrientationQuaternion(wheelIndex)
3385 Returns the wheel orientation as a quaternion.
3387 :arg wheelIndex: the wheel index
3388 :type wheelIndex: integer
3390 :return: TODO Description
3391 :rtype: TODO - type should be quat as per method name but from the code it looks like a matrix
3393 .. method:: getWheelPosition(wheelIndex)
3395 Returns the position of the specified wheel
3397 :arg wheelIndex: the wheel index
3398 :type wheelIndex: integer
3399 :return: position vector
3400 :rtype: list[x, y, z]
3402 .. method:: getWheelRotation(wheelIndex)
3404 Returns the rotation of the specified wheel
3406 :arg wheelIndex: the wheel index
3407 :type wheelIndex: integer
3409 :return: the wheel rotation
3412 .. method:: setRollInfluence(rollInfluece, wheelIndex)
3414 Set the specified wheel's roll influence.
3415 The higher the roll influence the more the vehicle will tend to roll over in corners.
3417 :arg rollInfluece: the wheel roll influence
3418 :type rollInfluece: float
3420 :arg wheelIndex: the wheel index
3421 :type wheelIndex: integer
3423 .. method:: setSteeringValue(steering, wheelIndex)
3425 Set the specified wheel's steering
3427 :arg steering: the wheel steering
3428 :type steering: float
3430 :arg wheelIndex: the wheel index
3431 :type wheelIndex: integer
3433 .. method:: setSuspensionCompression(compression, wheelIndex)
3435 Set the specified wheel's compression
3437 :arg compression: the wheel compression
3438 :type compression: float
3440 :arg wheelIndex: the wheel index
3441 :type wheelIndex: integer
3443 .. method:: setSuspensionDamping(damping, wheelIndex)
3445 Set the specified wheel's damping
3447 :arg damping: the wheel damping
3448 :type damping: float
3450 :arg wheelIndex: the wheel index
3451 :type wheelIndex: integer
3453 .. method:: setSuspensionStiffness(stiffness, wheelIndex)
3455 Set the specified wheel's stiffness
3457 :arg stiffness: the wheel stiffness
3458 :type stiffness: float
3460 :arg wheelIndex: the wheel index
3461 :type wheelIndex: integer
3463 .. method:: setTyreFriction(friction, wheelIndex)
3465 Set the specified wheel's tyre friction
3467 :arg friction: the tyre friction
3468 :type friction: float
3470 :arg wheelIndex: the wheel index
3471 :type wheelIndex: integer
3473 .. class:: KX_CharacterWrapper(PyObjectPlus)
3475 A wrapper to expose character physics options.
3477 .. attribute:: onGround
3479 Whether or not the character is on the ground. (read-only)
3483 .. attribute:: gravity
3485 The gravity value used for the character.
3491 The character jumps based on it's jump speed.
3493 .. class:: KX_VertexProxy(SCA_IObject)
3495 A vertex holds position, UV, color and normal information.
3498 The physics simulation is NOT currently updated - physics will not respond
3499 to changes in the vertex position.
3503 The position of the vertex.
3505 :type: list [x, y, z]
3509 The texture coordinates of the vertex.
3513 .. attribute:: normal
3515 The normal of the vertex.
3517 :type: list [nx, ny, nz]
3519 .. attribute:: color
3521 The color of the vertex.
3523 :type: list [r, g, b, a]
3525 Black = [0.0, 0.0, 0.0, 1.0], White = [1.0, 1.0, 1.0, 1.0]
3527 .. attribute:: colour
3533 The x coordinate of the vertex.
3539 The y coordinate of the vertex.
3545 The z coordinate of the vertex.
3551 The u texture coordinate of the vertex.
3557 The v texture coordinate of the vertex.
3563 The second u texture coordinate of the vertex.
3569 The second v texture coordinate of the vertex.
3575 The red component of the vertex color. 0.0 <= r <= 1.0.
3581 The green component of the vertex color. 0.0 <= g <= 1.0.
3587 The blue component of the vertex color. 0.0 <= b <= 1.0.
3593 The alpha component of the vertex color. 0.0 <= a <= 1.0.
3597 .. method:: getXYZ()
3599 Gets the position of this vertex.
3601 :return: this vertexes position in local coordinates.
3602 :rtype: list [x, y, z]
3604 .. method:: setXYZ(pos)
3606 Sets the position of this vertex.
3608 :type: list [x, y, z]
3610 :arg pos: the new position for this vertex in local coordinates.
3614 Gets the UV (texture) coordinates of this vertex.
3616 :return: this vertexes UV (texture) coordinates.
3619 .. method:: setUV(uv)
3621 Sets the UV (texture) coordinates of this vertex.
3625 .. method:: getUV2()
3627 Gets the 2nd UV (texture) coordinates of this vertex.
3629 :return: this vertexes UV (texture) coordinates.
3632 .. method:: setUV2(uv, unit)
3634 Sets the 2nd UV (texture) coordinates of this vertex.
3638 :arg unit: optional argument, FLAT==1, SECOND_UV==2, defaults to SECOND_UV
3641 .. method:: getRGBA()
3643 Gets the color of this vertex.
3645 The color is represented as four bytes packed into an integer value. The color is
3648 Since Python offers no way to get each byte without shifting, you must use the struct module to
3649 access color in an machine independent way.
3651 Because of this, it is suggested you use the r, g, b and a attributes or the color attribute instead.
3653 .. code-block:: python
3656 col = struct.unpack('4B', struct.pack('I', v.getRGBA()))
3657 # col = (r, g, b, a)
3658 # black = ( 0, 0, 0, 255)
3659 # white = (255, 255, 255, 255)
3661 :return: packed color. 4 byte integer with one byte per color channel in RGBA format.
3664 .. method:: setRGBA(col)
3666 Sets the color of this vertex.
3668 See getRGBA() for the format of col, and its relevant problems. Use the r, g, b and a attributes
3669 or the color attribute instead.
3671 setRGBA() also accepts a four component list as argument col. The list represents the color as [r, g, b, a]
3672 with black = [0.0, 0.0, 0.0, 1.0] and white = [1.0, 1.0, 1.0, 1.0]
3674 .. code-block:: python
3676 v.setRGBA(0xff0000ff) # Red
3677 v.setRGBA(0xff00ff00) # Green on little endian, transparent purple on big endian
3678 v.setRGBA([1.0, 0.0, 0.0, 1.0]) # Red
3679 v.setRGBA([0.0, 1.0, 0.0, 1.0]) # Green on all platforms.
3681 :arg col: the new color of this vertex in packed RGBA format.
3682 :type col: integer or list [r, g, b, a]
3684 .. method:: getNormal()
3686 Gets the normal vector of this vertex.
3688 :return: normalized normal vector.
3689 :rtype: list [nx, ny, nz]
3691 .. method:: setNormal(normal)
3693 Sets the normal vector of this vertex.
3695 :type: sequence of floats [r, g, b]
3697 :arg normal: the new normal of this vertex.
3699 .. class:: KX_VisibilityActuator(SCA_IActuator)
3701 Visibility Actuator.
3703 .. attribute:: visibility
3705 whether the actuator makes its parent object visible or invisible.
3709 .. attribute:: useOcclusion
3711 whether the actuator makes its parent object an occluder or not.
3715 .. attribute:: useRecursion
3717 whether the visibility/occlusion should be propagated to all children of the object.
3721 .. class:: SCA_2DFilterActuator(SCA_IActuator)
3723 Create, enable and disable 2D filters
3725 The following properties don't have an immediate effect.
3726 You must active the actuator to get the result.
3727 The actuator is not persistent: it automatically stops itself after setting up the filter
3728 but the filter remains active. To stop a filter you must activate the actuator with 'type'
3729 set to :data:`~bge.logic.RAS_2DFILTER_DISABLED` or :data:`~bge.logic.RAS_2DFILTER_NOFILTER`.
3731 .. attribute:: shaderText
3733 shader source code for custom shader.
3737 .. attribute:: disableMotionBlur
3739 action on motion blur: 0=enable, 1=disable.
3745 Type of 2D filter, use one of :ref:`these constants <Two-D-FilterActuator-mode>`
3749 .. attribute:: passNumber
3751 order number of filter in the stack of 2D filters. Filters are executed in increasing order of passNb.
3753 Only be one filter can be defined per passNb.
3755 :type: integer (0-100)
3757 .. attribute:: value
3759 argument for motion blur filter.
3761 :type: float (0.0-100.0)
3763 .. class:: SCA_ANDController(SCA_IController)
3765 An AND controller activates only when all linked sensors are activated.
3767 There are no special python methods for this controller.
3769 .. class:: SCA_ActuatorSensor(SCA_ISensor)
3771 Actuator sensor detect change in actuator state of the parent object.
3772 It generates a positive pulse if the corresponding actuator is activated
3773 and a negative pulse if the actuator is deactivated.
3775 .. attribute:: actuator
3777 the name of the actuator that the sensor is monitoring.
3781 .. class:: SCA_AlwaysSensor(SCA_ISensor)
3783 This sensor is always activated.
3785 .. class:: SCA_DelaySensor(SCA_ISensor)
3787 The Delay sensor generates positive and negative triggers at precise time,
3788 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.
3790 The duration parameter defines the length of the ON period following the OFF period.
3791 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.
3793 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).
3795 Use :class:`SCA_ISensor.reset` at any time to restart sensor.
3797 .. attribute:: delay
3799 length of the initial OFF period as number of frame, 0 for immediate trigger.
3803 .. attribute:: duration
3805 length of the ON period in number of frame after the initial OFF period.
3807 If duration is greater than 0, a negative trigger is sent at the end of the ON pulse.
3811 .. attribute:: repeat
3813 1 if the OFF-ON cycle should be repeated indefinately, 0 if it should run once.
3817 .. class:: SCA_JoystickSensor(SCA_ISensor)
3819 This sensor detects player joystick events.
3821 .. attribute:: axisValues
3823 The state of the joysticks axis as a list of values :data:`numAxis` long. (read-only).
3825 :type: list of ints.
3827 Each spesifying the value of an axis between -32767 and 32767 depending on how far the axis is pushed, 0 for nothing.
3828 The first 2 values are used by most joysticks and gamepads for directional control. 3rd and 4th values are only on some joysticks and can be used for arbitary controls.
3830 * left:[-32767, 0, ...]
3831 * right:[32767, 0, ...]
3832 * up:[0, -32767, ...]
3833 * down:[0, 32767, ...]
3835 .. attribute:: axisSingle
3837 like :data:`axisValues` but returns a single axis value that is set by the sensor. (read-only).
3843 Only use this for "Single Axis" type sensors otherwise it will raise an error.
3845 .. attribute:: hatValues
3847 The state of the joysticks hats as a list of values :data:`numHats` long. (read-only).
3851 Each spesifying the direction of the hat from 1 to 12, 0 when inactive.
3853 Hat directions are as follows...
3865 .. attribute:: hatSingle
3867 Like :data:`hatValues` but returns a single hat direction value that is set by the sensor. (read-only).
3871 .. attribute:: numAxis
3873 The number of axes for the joystick at this index. (read-only).
3877 .. attribute:: numButtons
3879 The number of buttons for the joystick at this index. (read-only).
3883 .. attribute:: numHats
3885 The number of hats for the joystick at this index. (read-only).
3889 .. attribute:: connected
3891 True if a joystick is connected at this joysticks index. (read-only).
3895 .. attribute:: index
3897 The joystick index to use (from 0 to 7). The first joystick is always 0.
3901 .. attribute:: threshold
3903 Axis threshold. Joystick axis motion below this threshold wont trigger an event. Use values between (0 and 32767), lower values are more sensitive.
3907 .. attribute:: button
3909 The button index the sensor reacts to (first button = 0). When the "All Events" toggle is set, this option has no effect.
3915 The axis this sensor reacts to, as a list of two values [axisIndex, axisDirection]
3917 * axisIndex: the axis index to use when detecting axis movement, 1=primary directional control, 2=secondary directional control.
3918 * axisDirection: 0=right, 1=up, 2=left, 3=down.
3920 :type: [integer, integer]
3924 The hat the sensor reacts to, as a list of two values: [hatIndex, hatDirection]
3926 * hatIndex: the hat index to use when detecting hat movement, 1=primary hat, 2=secondary hat (4 max).
3927 * hatDirection: 1-12.
3929 :type: [integer, integer]
3931 .. method:: getButtonActiveList()