Subscribe
 Post #1
 20th June 2007
mrflippy's Avatar
June 2005
541 Posts
I am attempting to attach an entity to an attachment point on a weapon (or other model). So far I have tried parenting the entity to the weapon and continuously setting the position in SWEP:Think(). Parenting seems to attach the entity in the middle of the character's body. Continuously setting the position works better, but is jerky, and I cannot figure out how to actually get the attachment's position. I am using

ent:SetPos(self.Weapon:GetAttachment(self.Weapon:LookupAttachment("muzzle")).Pos)

This gets fairly close to the muzzle, but is up above my head, and behaves strangely when I turn or move.

Is there another way to do this?

Edit:
I have put screenshots up here: http://mrflippy.net/images/screensho...od/flashlight/ (This is using setparentattachment)

Notice how the entity doesn't always match up with where the barrel of the gun is.
 Post #2
 20th June 2007
Gold Member
Catdaemon's Avatar
February 2005
11,542 Posts
Get the shootpos, stick it there and then parent it to the gun without setting any attachments.
 Post #3
 20th June 2007
Gold Member
jA_cOp's Avatar
May 2006
4,833 Posts
Catdaemon posted:
Get the shootpos, stick it there and then parent it to the gun without setting any attachments.
Shootpos isn't the gun pos at all, simply the screen position.

And parenting to the gun makes movement of the parented entity inverted.

 Post #4
 20th June 2007
Gold Member
Catdaemon's Avatar
February 2005
11,542 Posts
jA_cOp posted:
Shootpos isn't the gun pos at all, simply the screen position.
There's a function serverside that returns the position of the end of the gun.
 Post #5
 20th June 2007
Super Moderator
SteveUK's Avatar
May 2005
4,000 Posts
In the Source SDK SetParent() has an additional parameter for the attachment, I don't know if it's in the Lua implementation.

Edit: talked to Garry on Gtalk, apparently this isn't avaliable yet, and has added it to the next release.
 Post #6
 20th June 2007
Gold Member
Catdaemon's Avatar
February 2005
11,542 Posts
SteveUK posted:
In the Source SDK SetParent() has an additional parameter for the attachment, I don't know if it's in the Lua implementation.

Edit: talked to Garry on Gtalk, apparently this isn't avaliable yet, and has added it to the next release.
You can do it through ent:Fire.
entity:Fire("setparentattachment","eyes",0)
 Post #7
 20th June 2007
mrflippy's Avatar
June 2005
541 Posts
Catdaemon posted:
Get the shootpos, stick it there and then parent it to the gun without setting any attachments.
Setting something to the shootpos sticks the ent in the players head or something.

Edit:

SteveUK posted:
In the Source SDK SetParent() has an additional parameter for the attachment, I don't know if it's in the Lua implementation.

Edit: talked to Garry on Gtalk, apparently this isn't avaliable yet, and has added it to the next release.
This would be pretty nice.

Edit:

Catdaemon posted:
You can do it through ent:Fire.
entity:Fire("setparentattachment","eyes",0)
Hmm... this seems to work better than anything else that I have tried. It still behaves a bit oddly, but not as oddly as before.

Edit: That is the first-person view is weird -- the entity swings way over to the right or left when I turn that direction, and bounces a lot when I move. Looks great from third-person though I think

Screenshots of the latest code using setparentattachment.
Reply


All times are GMT. The time now is 04:24PM.

Facepunch Studios 2009 - Server 'Softlayer 2.0'