• Spawn entity at eyeTrace
    4 replies, posted
So this may sound simple, And it probably is but for the life of me I cannot figure it out. I Want it so when I spawn an entity(with code) it will spawn at the players looking position and will not be click into the wall. Also if they are looking to far away then just spawn it in front of the player. This is my code right now(does not work correctly) [CODE]local eyeTrace = self:GetEyeTrace() local spawnPos = eyeTrace.HitPos if spawnPos:Distance(self:GetPos()) > 150 then --This is just to make sure it does not spawn miles into the distance spawnPos = spawnPos:GetNormalized() spawnPos:Mul(150) spawnPos = self:GetPos() + spawnPos end local temp = ents.Create("item_base") temp:SetPos(spawnPos) temp:InitItem(self.inventory[slot].itemName , amount) temp:Spawn()[/CODE]
It's because you're trying to normalize and use a vector position as a vector direction. This is creating a directional vector from (0, 0, 0) -> aimPos; not plyPos -> aimPos. Use #GetAimVector to obtain the normalized vector direction of where the player is looking.
[QUOTE=vexx21322;47666688]It's because you're trying to normalize and use a vector position as a vector direction. This is creating a directional vector from (0, 0, 0) -> aimPos; not plyPos -> aimPos. Use #GetAimVector to obtain the normalized vector direction of where the player is looking.[/QUOTE] Thanks, Now what about the object clipping into the walls etc
[QUOTE=0V3RR1D3;47666773]Thanks, Now what about the object clipping into the walls etc[/QUOTE] You would want to move the entity along the normal of the faces that it's clipping in. You could use traces to obtain the normals of nearby surfaces.
[QUOTE=vexx21322;47667217]You would want to move the entity along the normal of the faces that it's clipping in. You could use traces to obtain the normals of nearby surfaces.[/QUOTE] Oh, I Did not know that, Thanks!
Sorry, you need to Log In to post a reply to this thread.