Game Object: worldPosition

worldPosition
  • gets/sets the game object's world position

Type:

  • float list [ x, y, z]
  • x: position on the world x-axis
     
  • y: position on the world y-axis
     
  • z: position on the world z-axis
Sample Code

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

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

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

# get the world position
posWorld = obj.worldPosition

Sample Code

################## set the game object's world position
 
# 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 world position
obj.worldPosition = [ 2.0, 0.0, 1.0 ]