Hey, I am trying to make an entity get stuck to your back when you use it, and I know it's done using the ENT:SetParent() function. But it moves too much when a player perform a small movement like look at something. I know this is because it's connected to a bone that moves a lot. But Is there a way to make it move less and with the actual back/spine of the player. I've noticed that a lot of models doesn't have the chest attachment so how would I solve that? I want the prop to go like this on the back: [IMG]https://s3.scriptfodder.com/script_media/4c83d0e0b0830f4dfb1ac7e1aeab4189.png[/IMG]
[url]https://s3.scriptfodder.com/script_media/4c83d0e0b0830f4dfb1ac7e1aeab4189.png[/url]
What hook are you using to set it's position? You practically need to set the position before it, and the player is drawn.
This is what I did in my latest attempt:
[CODE]function ENT:Use(act,caller)
if(!IsValid(act)) then return end
self:PhysicsInit(SOLID_NONE)
self:SetSolid(SOLID_NONE)
local id = act:LookupAttachment("chest")
local att = act:GetAttachment( id )
self:SetPos(att.Pos)
self:SetParent(act,id)
end
[/CODE]
Try doing [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/AddEffects]Entity:AddEffects[/url] with the effect being EF_BONEMERGE
How would you set the bone to merge to with that?
That helped and made the model not move as much and move better with the actual bone. But how would I go and set the position of the model and make it stay there? The method I used in the code example doesn't have any effect. The model is just put at the players feet. I also tried ENT:SetLocalPos() after I made it the parent but it doesn't want to move.
Take a look at that, I hope this coulds help you.
I had too a similar problem for attachment but solved it with this code:
[CODE]
function tf2remake_attachment_attach(ent,ply)
if ply:IsPlayer() and ply:IsValid() then
ent:SetNoDraw(true)
ent:SetMoveType(MOVETYPE_NONE)
ent:SetCollisionGroup(COLLISION_GROUP_DEBRIS)
ent:SetParent(ply)
ent:Fire("SetParentAttachment","chest",0.01)
timer.Simple(0.016,function() if ent:IsValid() and ply:IsValid() then ent:SetLocalPos(Vector(-11,0,-5)) ent:SetLocalAngles(Angle(0,-90,92)) end end)
timer.Simple(0.033,function() if ent:IsValid() and ply:IsValid() then ent:SetNoDraw(false) end end)
else
tf2remake_dev_addevent("Attachment(ATTACH) failed on "..tostring(ply)..". Not a player or is not valid.","ERROR")
end
end
[/CODE]
Thank you Gedo, it worked.
[editline]27th June 2016[/editline]
Guess it's worth saying that if the model doesn't have the "chest" attachment you can use the "eyes". It seems to act kinda like "chest" would. And "eyes" is something more models have.
Sorry, you need to Log In to post a reply to this thread.