ClientsideModel

So iv’e been trying to make models appear on players and iv’e managed to do it but whenever the player looks down, up, left or right the model seems to follow there eye position. Is there anyway to make it stay in on place but turn if the player turns like it does with pointshop?

when it firsts spawns on the player:

http://s18.postimg.org/onz7xnoeh/4000_screenshots_20160921175043_1.jpg

when the player looks down/up:

http://s16.postimg.org/uf0o0g091/4000_screenshots_20160921175045_1.jpg

here’s my code:




        local bone = LocalPlayer():LookupBone("ValveBiped.Bip01_Spine2")
	             
	local matrix = LocalPlayer():GetBoneMatrix(bone)
	local pos = matrix:GetTranslation()
	local ang = matrix:GetAngles()
 
	pos = pos + LocalPlayer():GetForward() * 0 + LocalPlayer():GetRight() * 0 + LocalPlayer():GetUp() * 20

	local AttachedModel=ClientsideModel("models/modified/backpack_2.mdl",RENDERGROUP_OPAQUE)
   	AttachedModel:SetParent(LocalPlayer())
   	AttachedModel:SetPos(pos)
	AttachedModel:SetAngles(ang)
	AttachedModel:SetRenderOrigin(pos)
	AttachedModel:SetRenderAngles(ang)
	AttachedModel:SetupBones()
	AttachedModel:DrawModel()
	AttachedModel:SetRenderOrigin()
	AttachedModel:SetRenderAngles()


Try http://wiki.garrysmod.com/page/Entity/SetParentPhysNum, you want to specify where its parented on players/ragdolls.

Like this??



        local bone = LocalPlayer():LookupBone("ValveBiped.Bip01_Spine2")
	             
	local matrix = LocalPlayer():GetBoneMatrix(bone)
	local pos = matrix:GetTranslation()
	local ang = matrix:GetAngles()

	pos = pos + LocalPlayer():GetForward() * 0 + LocalPlayer():GetRight() * 0 + LocalPlayer():GetUp() * 20

	local AttachedModel=ClientsideModel("models/modified/backpack_2.mdl", RENDERGROUP_OPAQUE)
	AttachedModel:SetParent( LocalPlayer() )
   	AttachedModel:SetParentPhysNum( bone )
   	AttachedModel:SetPos(pos)
	AttachedModel:SetAngles(ang)
	AttachedModel:SetRenderOrigin(pos)
	AttachedModel:SetRenderAngles(ang)
	AttachedModel:SetupBones()
	AttachedModel:DrawModel()
	AttachedModel:SetRenderOrigin()
	AttachedModel:SetRenderAngles()


if i do it without AttachedModel:SetParent( LocalPlayer() ) then it just floats in mid air

If you can’t get that working, you can try “setparentattachmentmaintainoffset”

http://forum.facepunch.com/showthread.php?t=1533237&p=51010344

I don’t remember if it works for clientside entities, though. Also, you should check to make sure the bone lookup is working. Print it and make sure it’s not -1.
I think this function you’re trying to use requires a physics bone not a regular bone. It might want a bone that is part of a ragdoll, not a player.

It does indeed need a physical bone, I believe. Tested and it only seems to work on ragdolls.

Perhaps this might be of help: http://wiki.garrysmod.com/page/Entity/FollowBone

I haven’t tried this but this seems to be the correct thing.

Awesome it worked, thanks for the help

[editline]23rd September 2016[/editline]

oh never mind. got another problem now, when the model spawns it spawns in different positions depending on where the player was looking when it spawned :confused:

looking forward when it spawns:

http://s21.postimg.org/5dpycyuk7/4000_screenshots_20160923212552_1.jpg

looking up when it spawns:

http://s10.postimg.org/wbvlah3vt/4000_screenshots_20160923212609_1.jpg

rather than using ‘LocalPlayer():GetForward()’ try using something like this:


local BonePos, BoneAng = LocalPlayer():GetBonePosition( LocalPlayer():LookupBone( "BoneNameOrSomething" ) )

pos = pos + BoneAng:Forward() * 0 + BoneAng:Right() * 0 + BoneAng:Up() * 20