• Help With Parenting Entities
    3 replies, posted
so i want to parent my entities to another and position it.Can someone explain the basis with which folder it goes to ?
It depends what type of parenting you're referring to. You are talking about folders and positioning it to another so I'll assume you're talking about spawning an entity, positioning it on another and parenting it / bone-merging it so that it stays with the new entity? First, folders and hierarchy / inheritance: Entities would go into addons/addon-name/lua/entities/ or garrysmod/lua/entities/ or gamemodes/gamemode-name/entities/entities/ ( or weapons, etc ). Depending on the entity type, the parent entity that you're extending functionality of would be set as ENT.Base = "base_entity" or SWEP.Base = "weapon_base" All of base_entity or weapon_base then exist inside the new entity or weapon. If you create a function in the new entity or swep which already exists in the base then you're overwriting it meaning it won't run in the base but will run in the current entity. Now, for spawning, positioning and parenting ( in that order )... You'd have either a base entity ( say the player ) you'd want to parent something to. So you spawn the new entity ( depending on the type you'd spawn something else but if it is just a simple model like a hat a prop_dynamic works well ) Spawn the prop_dynamic as local _hat = ents.Create..., set the model then you'd position it relative to the parent. Use LocalToWorld and LocalToWorldAngles for it so that the returned position will be a world position that'll match up with the relative position to the player _p you want the hat to be positioned and angled at. _hat:SetPos( _p:LocalToWorld( Vector( 0, 0, 72 ) ) ); _hat:SetAngles( _p:LocalToWorldAngles( Angle( 0, 90, 0 ) ) ); Then, you'll want to either bone-merge it or parent it, then spawn / activate it. _hat:SetParent( _p ); _hat:Spawn( ); _hat:Activate( ); Now; using entities for effects like this isn't always a good idea... You have to account for PVS with entities, so when the player leaves the LocalPlayer( ) PVS you'll need to ensure the child entity is hidden ( otherwise you may be left with floating entities around the map ). Another method would be to use client-side models and position / render them each frame in relation to the bone, or bone-merge them and render them when the player / parent entity is visible... Hopefully this helps.
Thanks seems complicated but i will try to do it :D
Well, depends what exactly you're doing... I defined a few scenarios... What exactly are you trying to do? It'd help narrow down the explanation.
Sorry, you need to Log In to post a reply to this thread.