GetBonePosition (How to use it)

Well I am trying to make a blood effect come out of your head so…

I finished the effect (works perfectly)

Then I used the GetBonePosition to get the position of my head…

When i tested it out…

the effect came out of my ShootPos

so my question is:

How do you use GetBonePosition?

Here’s the code that I used for the GetBonePositon:

[lua]
function SWEP:SecondaryAttack()
self.Weapon:SetNextSecondaryFire(CurTime() + 0.01)

local BoneIndx = self.Owner:LookupBone("ValveBiped.Bip01_Head1")
local BonePos = self.Owner:GetBonePosition( BoneIndx )

local edd = EffectData()
edd:SetOrigin( BonePos )
edd:SetStart( BonePos )
edd:SetAttachment( 1 )
edd:SetEntity( self.Weapon )
util.Effect( "BloodCore", edd )

end
[/lua]

And yes I did look at the wiki already. Not really helpful.

Try printing BonePos to see what you get.

ok

Bone related functions usually act funky when used serverside. The server shouldn’t do that job for you anyway, anything effect related should be done on the client, and since the client perfectly knows where that player is on your screen, it should be most suitable one for that job.
You should make a clientside effect that spawns blood at a player’s head, and then spawn that effect serverside after feeding it with self.Owner via edd:SetEntity(self.Owner).

If this still fails, try using GetBoneMatrix. I always use it, as I occasionally get extremely weird results with GetBonePosition.

[lua]local BoneIndx = ent:LookupBone(“ValveBiped.Bip01_Head1”)
local BonePos = ent:GetBoneMatrix(BoneIndx):GetTranslation()[/lua]

thnx and i got this for the BonePosition:

HeadPos = 986.5160 -659.8004 -87.0905

That’s totally helpful. :downs: Common sense, god damnit, you should print the results of GetShootPos and GetBonePosition at the same time and compare them, else it’s just utterly useless.

Can you show me how to use GetBoneMatrix?

Cause there is no example for it on the Gmod Wiki.

EDIT:

HeadPos = 698.5015 -203.9544 -82.9842

ShootPos = 703.3870 -209.3440 -78.0000

Looks weird to me, the ShootPos is higher than your head.

I just posted an example of how you should use it. :downs:

Thank you very much :slight_smile:

[lua]
edd:SetAttachment( 1 )
edd:SetEntity( self.Weapon )
[/lua]

Could these lines be the problem?

Well if I set the entity to self.Owner then it would show up at my feet.