Game Object: setParent

setParent(parent, compound, ghost)
  • Makes this game object a child of another game object.

parent:

  • Game object to be used as a parent for this game object.
  • Type:  string or KX_GameObject
compound:
  • Combine the child's shape with the parent's shape
  • Type:  boolean
  • enabled: 1 or True
  • disabled: 0 or False
ghost:
  • Child is set to ghost (no collisions).
  • Type:  boolean
  • enabled: 1 or True
  • disabled: 0 or False
Sample Code

################## set parent
  

# import bge
import bge

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

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

# get current scene
scene = bge.logic.getCurrentScene()

# get object list
objList = scene.objects

# get object named MainCharacter
parent = objList["MainCharacter"]

# combine child's shape with parent's
compound = True

# child is solid
ghost = False

# set parent
obj.setParent( parent, compound, ghost)