I've been trying to parent an entity to the player, but I always get crazy offsets because the parenting always happens relative to the player's parented bone. It never parents in the same place and I'd like for it to also not move around once properly positioned, just follow the player around instead, is there any way to do this?
Basically I'd like to parent the entity exactly 40 units above the center of the player and no matter what happens it always spawns in the same spot and stays there, relative to the player's getpos of course. I'm about to create a network condition and spawn a clientside entity and move it above the head every call on it's think hook because I can't get it to do what I want.
For refrence my current code is this:
[code]local ent = ents.Create("prop_physics")
ent:SetModel("models/roller.mdl")
ent:Spawn()
ent:SetMoveType( MOVETYPE_NONE )
ent:PhysicsInit( SOLID_NONE )
ent:SetSolid(SOLID_NONE)
ent:SetParent(ply)
ent:SetPos(ply:GetPos() + Vector(0, 0, 40))[/code]
I was using ent:SetPos(ply:LocalToWorld(ply:OBBCenter()) + Vector(0,0,40)) but I don't think that's quite right.
Also I was going to set the attachment but none of them are really an "unmoving center of mass that doesn't change position when the yaw changes" kind of attachment point.
I tested this on my singleplayer luapad and it seemed to work perfectly fine.
Note: Clientside it'll look like the rollermine is moving along with the players head, but to other players it'll be seen as stationary above the players position.
I think a main problem is that the rollermine prop, like others, tends to fall half into the ground at ply:GetPos(), so you'll have to tinker with the amount of "up" you add to its pos, because 40 clearly wasn't enough.
[CODE]local ent = ents.Create("prop_physics")
ent:SetModel("models/roller.mdl")
ent:SetMoveType( MOVETYPE_NONE )
ent:PhysicsInit( SOLID_NONE )
ent:SetSolid(SOLID_NONE)
ent:SetPos(ply:GetPos() + Vector(0, 0, 90))
ent:SetParent(ply)
ent:SetOwner(ply)
ent:Spawn()
[/CODE]
Sorry, you need to Log In to post a reply to this thread.