Game Object: worldTransform

worldTransform
  • gets/sets the game object's world Transform

Type:

  • float Matrix 4 x 4
Note:
  • A world transform changes game object's coordinates, where vertices are defined relative to a model's origin.
     
  • gets/sets the model's scale, orientation and position.
Sample Code

################## get the game object's world transform
 
# import bge
import bge

# get controller
cont = bge.logic.getCurrentController()

# get object that controller is attached to
obj = cont.owner

# get the world transform
trans = obj.worldTransform

Sample Code 1

################## set the game object's scale on x, y and z
 
# import bge
import bge

# get controller
cont = bge.logic.getCurrentController()

# get object that controller is attached to
obj = cont.owner

# set the game object's scale on x, y and z axis to 2.5
obj.worldTransform = [[ 2.5, 0.0, 0.0 ,0.0],[ 0.0, 2.5, 0.0, 0.0],[ 0.0, 0.0, 2.5, 0.0],[ 0.0, 0.0, 0.0, 1.0]]

Sample Code 2

################## set the game object's position on x, y and z axis
 
# import bge
import bge

# get controller
cont = bge.logic.getCurrentController()

# get object that controller is attached to
obj = cont.owner

# set the game object's position on x, y and z axis to 3.0, 2.0, 4.5
obj.worldTransform = [[ 1.0, 0.0, 0.0 ,3.0],[ 0.0, 1.0, 0.0, 2.0],[ 0.0, 0.0, 1.0, 4.5],[ 0.0, 0.0, 0.0, 1.0]]

Sample Code 3

################## set the game object's orientation on x, y and z axis
 
# import bge
import bge

# get controller
cont = bge.logic.getCurrentController()

# get object that controller is attached to
obj = cont.owner

# set the game object's orientation on y to 45 degrees (uses cosine of the angles)
obj.worldTransform = [[ 0.7071, 0.0, 0.7071 ,0.0],[ 0.0, 1.0, 0.0, 0.0],[ -0.7071, 0.0, 0.7071, 0.0],[ 0.0, 0.0, 0.0, 1.0]]

Sample Code 4

################## set the game object's scale, position, orientation
 
# import bge
import bge

# get controller
cont = bge.logic.getCurrentController()

# get object that controller is attached to
obj = cont.owner

# set the game object's orientation on y to 45 degrees (uses cosine of the angles)
# set game object's position to [3.0, 2.0, 4.5]
# set game object's scale to 2 on x, y and z axis ( multiply scale by orientation -- 2.0 * 0.7071)

obj.worldTransform = [[ 1.4142, 0.0, 1.4142 ,3.0],[ 0.0, 2.0, 0.0, 3.0],[ -1.4142, 0.0, 1.4142, 4.5],[ 0.0, 0.0, 0.0, 1.0]]