Blitz3D+ Command Reference

GetParent ( entity )

Parameters

entity - entity handle

Description

Returns an entity's parent, or 0 if it has none.

Useful when you have hold of one part of a hierarchy and need the thing it belongs to - a pick or collision might return a wheel when your game logic wants the whole car. Walk up with GetParent (repeatedly, if the model is nested) until you reach the root entity, which returns 0 for its parent.

Parents are assigned with the parent parameter of the create/load commands or with EntityParent.

See also: EntityParent, CountChildren, GetChild, FindChild.

Example

; GetParent Example
; -----------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,4,-10
RotateEntity camera,18,0,0

light=CreateLight()
RotateEntity light,45,45,0

; A tank body with a turret parented on top
body=CreateCube()
ScaleMesh body,1.5,0.5,1
EntityColor body,0,150,0

; ScaleMesh (not ScaleEntity) is used on the body so the child is not distorted
turret=CreateCube(body)
ScaleMesh turret,0.5,0.3,1.2
PositionEntity turret,0,0.8,0
EntityColor turret,0,220,80

While Not KeyDown(1)

    ; The tank drives in a circle; the turret scans independently but,
    ; being a child, is carried along with its parent
    TurnEntity body,0,1,0
    MoveEntity body,0,0,0.08
    TurnEntity turret,0,2,0

    ; Arrow keys move the camera
    If KeyDown(200) Then MoveEntity camera,0,0,0.1
    If KeyDown(208) Then MoveEntity camera,0,0,-0.1
    If KeyDown(203) Then TurnEntity camera,0,1,0
    If KeyDown(205) Then TurnEntity camera,0,-1,0

    RenderWorld

    Text 0,0,"Arrow keys: move camera   Esc: exit"
    ; GetParent returns the handle of an entity's parent, or 0 for no parent
    Text 0,20,"GetParent(turret) = "+GetParent(turret)+"   (body = "+body+")"
    Text 0,40,"GetParent(body) = "+GetParent(body)+"   (0 = no parent)"

    Flip

Wend

End

Index