Entity/SetParent

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
(Added instruction to solve the problem with children's non-static PhysObj)
m (Fixed language mistake)
Line 2: Line 2:
 
|Description=Sets the parent of this entity, making it move with its parent.
 
|Description=Sets the parent of this entity, making it move with its parent.
  
If you move solid entities, they probably have a {{Type|PhysObj}}. The {{ClassFunction|Entity|Spawn}} method creates a static {{Type|PhysObj}} for a few classes such as solid ''prop_dynamic'', which will never move without the entity it belongs to. Otherwise it creates a dynamic {{Type|PhysObj}}, '''which will fall on the ground when pushed or when the parent moves! '''{{ClassFunction|Entity|PhysicsInit}} always creates a dynamic {{Type|PhysObj}} whatever the class is. One solution for children with a dynamic {{Type|PhysObj}} is to destroy it with {{ClassFunction|Entity|PhysicsDestroy}}() and make sure to avoid {{Type|Player}}s colliding with them with {{ClassFunction|Entity|PhysicsDestroy}}( COLLISION_GROUP_WEAPON ), otherwise {{Type|Player}}s can get stuck when touching the child.
+
If an {{Type|Entity}} is solid, it probably has a {{Type|PhysObj}}. The {{ClassFunction|Entity|Spawn}} method creates a static {{Type|PhysObj}} for a few classes such as solid ''prop_dynamic'', which will never move without the entity it belongs to. Otherwise it creates a dynamic {{Type|PhysObj}}, '''which will fall on the ground when pushed or when the parent moves! '''{{ClassFunction|Entity|PhysicsInit}} always creates a dynamic {{Type|PhysObj}} whatever the class is. One solution for children with a dynamic {{Type|PhysObj}} is to destroy it with {{ClassFunction|Entity|PhysicsDestroy}}() and make sure to avoid {{Type|Player}}s colliding with them with {{ClassFunction|Entity|PhysicsDestroy}}( COLLISION_GROUP_WEAPON ), otherwise {{Type|Player}}s can get stuck when touching the child.
 
|Realm=Shared
 
|Realm=Shared
 
|IsClass=Yes
 
|IsClass=Yes

Revision as of 12:17, 8 April 2017

 Entity:SetParent( )

Description

Sets the parent of this entity, making it move with its parent.

If an Entity is solid, it probably has a PhysObj. The Entity:Spawn method creates a static PhysObj for a few classes such as solid prop_dynamic, which will never move without the entity it belongs to. Otherwise it creates a dynamic PhysObj, which will fall on the ground when pushed or when the parent moves! Entity:PhysicsInit always creates a dynamic PhysObj whatever the class is. One solution for children with a dynamic PhysObj is to destroy it with Entity:PhysicsDestroy() and make sure to avoid Players colliding with them with Entity:PhysicsDestroy( COLLISION_GROUP_WEAPON ), otherwise Players can get stuck when touching the child.

Arguments

Entity parent

The entity to parent to. Setting this to nil will clear the parent.

Arguments

number attachmentId=-1

The attachment id to use when parenting, defaults to -1 or whatever the parent had set previously.

NOTE

You must call Entity:SetMoveType( MOVETYPE_NONE ) on the child for this argument to have any effect!

Personal tools
Navigation