How can I directly connect the object to the bone \ attachments? For example any prop to "Rig_Buggy.Gun" bone or "gun_ref" attachment? Tried to do it with SetAttachment, parent, but could not. Any ideas, examples?
I've been able to accomplish this by using [URL="http://wiki.garrysmod.com/?title=Entity.Fire"]Entity.Fire[/URL] and the [URL="https://developer.valvesoftware.com/wiki/Entity_Hierarchy_(parenting)"]entity parenting inputs.[/URL] You can either use setparentattachment or setparentattachmentmaintainoffset in order to parent it directly to the attachment or from the position it's already in. In the end, it should look something like either of these.
[CODE]self.Entity:Fire("setparentattachment", "gun_ref", 0)
self.Entity:Fire("setparentattachmentmaintainoffset", "gun_ref", 0)[/CODE]
thanks for the help, but could you show any example? I've never used this function before, and I do not know how to use it
my attempt:
[CODE]hook.Add("PlayerSpawnedVehicle","attachtobone",function( ply, vehicle )
local model = ents.Create("prop_physics")
model:SetModel("models/props_c17/GasPipes006a.mdl")
model:SetPos( vehicle:GetPos())
model:SetAngles( vehicle:GetAngles())
vehicle:DeleteOnRemove(model)
model:Fire("setparentattachment", "gun_ref", 0)
model:Spawn()
end)
[/CODE]
Everything shown there is correctly done, except you didn't parent the entity to the actual object you want it to be attached to first. What should be done should be something along the lines of.
[CODE]hook.Add("PlayerSpawnedVehicle","attachtobone",function( ply, vehicle )
local model = ents.Create("prop_physics")
model:SetModel("models/props_c17/GasPipes006a.mdl")
model:SetPos( vehicle:GetPos())
model:SetAngles( vehicle:GetAngles())
vehicle:DeleteOnRemove(model)
model:SetParent(vehicle) // Note that the parent must be set before firing setparentattachment
model:Spawn()
model:Fire("setparentattachment", "gun_ref", 0.01) // Has a 0.01 delay just to make sure as the wiki does say that there must be at least a 0.01 second delay after parenting the prop before firing this input.
end)[/CODE]
YAY! Its works!!
[IMG]http://dl.dropbox.com/u/30024212/YAAY.jpg[/IMG]
Many thanks for your help, very grateful!
does anyone here have the documentation for setparentattachment.
does it work on playerbones
[QUOTE=LauScript;33922693]does anyone here have the documentation for setparentattachment.[/QUOTE]
The documentation is found on [URL="https://developer.valvesoftware.com/wiki/Entity_Hierarchy_(parenting)"]the page I had linked before[/URL].
[QUOTE=LauScript;33922693]does it work on playerbones[/QUOTE]
Yes it does, a quick example from my actual usage of this would be this after parenting the entity to the player.
[CODE]self.Entity:Fire("setparentattachment", "anim_attachment_RH", 0)[/CODE]
also, how to flip an entity that is already attached? (turn around Z?)
You'll have to manually set the position and the angle before using setparentattachmentmaintainoffset. The way I was able to do this on a player was by getting the bone's position and angle and setting the entity to that as well as changing the entities angle to the angle of the bone. Here's a snippet of what I actually did for this, of course though, your situation is more than likely going to need to be done differently.
[CODE]
par = self.Entity:GetParent()
hand = par:LookupBone("ValveBiped.Anim_Attachment_RH")
pos, ang = par:GetBonePosition( hand )
self.Entity:SetPos(par:GetPos() - pos + Vector(0,0,pos.z*1.3))
self.Entity:SetAngles(ang + Angle(0,0,90))
self.Entity:Fire("setparentattachmentmaintainoffset", "anim_attachment_RH", 0)
[/CODE]
Skipping straight to the point:
This is the error i got :[code] "ERROR: Tried to SetParentAttachmentMaintainOffset for entity prop_physics (prop_physics), but it has no attachment named ValveBiped.Bip01_R_Hand.
]"[/code]
This is what I did to apply it:
[code]
player.GetByID(1):AttachEntToBone( "models/props_junk/PopCan01a.mdl", "ValveBiped.Bip01_R_Hand", Vector(0,0,0), Angle(0,0,0) )
[/code]
Here is the source code:
[lua]
function _R.Player:AttachEntToBone( strmodel, strbone, vecboneoffset, angboneoffset )
local boneindex = self:LookupBone( strbone );
local vecorigin, angorigin = self:GetBonePosition( boneindex );
local attachment = ents.Create("prop_physics")
attachment:SetModel("models/props_c17/GasPipes006a.mdl");
attachment:SetPos( vecorigin + vecboneoffset );
attachment:SetAngles( angorigin + angboneoffset );
attachment:SetParent(self);
attachment:Spawn()
attachment:Fire("setparentattachmentmaintainoffset", strbone, 0.01)
end
[/lua]
I also tried the same thing except with the bone set to "ValveBiped.Anim_Attachment_RH":
and i got the error: ERROR: Tried to SetParentAttachmentMaintainOffset for entity prop_physics (prop_physics), but it has no attachment named ValveBiped.Anim_Attachment_RH.
]
[code]
AttachEntToBone( "models/props_junk/PopCan01a.mdl", "ValveBiped.Anim_Attachment_RH", Vector(0,0,0), Angle(0,0,0) )
[/code]
After running both of these things this is the result:
[url]http://cloud.steampowered.com/ugc/612720649852577718/76C4149AA9F4E5506B154CEE819D1EE444BDC73A/[/url]
When using setparentattachmentmaintainoffset, you'll need to get rid of the "ValveBiped." part as that's not the actual name of the attachment, whereas Entity.GetBonePosition does require the "ValveBiped." part. You can use string.sub on strbone in your situation to return only what's after that part before running the input.
That didn't fix it.
Bip01_Head1
or Anim_attachment_RH
I may be...no I am...Okay so I'm reviving an old thread but, it's for a good cause. I was wondering if anyone figured out how to attach bones onto players.
Attach [B]bones [/B]onto [B]players[/B]? That's not exactly possible.
[QUOTE=Robotboy655;43015701]Attach [B]bones [/B]onto [B]players[/B]? That's not exactly possible.[/QUOTE]
Technically it is because an entity with only one bone is still a bone :D
Like bonemerge almost if you guys remember that.
[editline]29th November 2013[/editline]
I got this so far:
[CODE] person = ents.Create("prop_dynamic")
person:SetModel( "models/props_c17/SuitCase_Passenger_Physics.mdl" )
person:SetPos( client:GetPos() )
person:SetAngles( Angle(0,90,90) )
client:DeleteOnRemove(person)
person:SetParent( client )
person:Fire("setparentattachment", "Anim_Attachment_RH", 0.01 )[/CODE]
But it doesn't really fit the angle of the hand correctly. Any way to fix the angle?
SetLocalAngle
SetLocalPos
You can't add new bones to anything.
SetLocalAngle and SetLocalPos doesn't seem to work. Although, I did strangely get my character to go to Vector(0,0,0) in the map.
[QUOTE=pilot;43023286]SetLocalAngle and SetLocalPos doesn't seem to work. Although, I did strangely get my character to go to Vector(0,0,0) in the map.[/QUOTE]
You are using them incorrectly then. You gotta use them on your "person" entity.