Does anyone understand the ghostentity code?

I’m trying to make something similar as the ghost entity used in many of the gmod tools but am having a hard time deciphering it. Some of the tools that use it are easy weld, axis, and ball socket. I have tried using the code from the dynamite and button but it only works for a few props. Most props have the ghost entity collide inside the object I’m looking at.

What I want to do is be able to choose a prop from a menu (not by clicking on a physical prop like the duplicator), and then when I go back to the tool gun, have a ghost prop where I’m looking at. The hardest part about this is making sure everything lines up properly and things don’t collide.

Here’s the ghost entity code from the gmod_tool.
and it also uses many functions from the object code

I’m mainly trying to decipher these couple lines as I dont want it to use any functions from the object code. I want it to be based purely off my selected prop from the menu and whatever I’m looking at.
local Ang1, Ang2 = self:GetNormal(1):Angle(), (trace.HitNormal * -1):Angle()
local TargetAngle = self:GetEnt(1):AlignAngles( Ang1, Ang2 )

self.GhostEntity:SetPos( self:GetEnt(1):GetPos() )
self.GhostEntity:SetAngles( TargetAngle )

local TranslatedPos = self.GhostEntity:LocalToWorld( self:GetLocalPos(1) )
local TargetPos = trace.HitPos + (self:GetEnt(1):GetPos() - TranslatedPos) + (trace.HitNormal)


I’m not quite understanding what you’re wanting. Are you just wanting to know what that code does? Or are you saying it collides and want help with that?

Those 2 links I posted along with that little code snippet is code from the gmod tool. I want to know how to make it work WITHOUT using the functions from object.lua (the second link.
In the code snippet I posted the functions GetEnt, GetNormal, and GetLocalPos are from object.lua. I want it to find all that information without going through those funcitons.

To give you an idea of what I mean, here is one of my attempts with just the position:
local TranslatedPos = self.GhostProp:LocalToWorld( self.GhostProp:GetPos() )
local TargetPos = trace.HitPos + (self.GhostProp:GetPos() - TranslatedPos) + (trace.HitNormal)
The above code causes the ghost prop to flash back and forth between two spots. It is because the translatedPos jumps back and forth between 2 values (if im stationary). I believe this is being caused by the LocalToWorld function which I dont fully understand yet.

[editline]7th January 2011[/editline]

This is one of the tools that uses the ghostEntity

I should’ve paid more attention in geometry class, but uh, I found a really old file that may be able to help you. I’m going to test it out first and see if I can get it to work.

Well even spawning props through the menu can cause other props to spawn inside of each other. But you could get the bounding box, use findinbox(), and either get their positions, bounding boxes, and vectors and just move accordingly or just no collide with them.

Here, it won’t go through the ground or through anything you can’t see through.
local function TestGhostProp()
local vStart = LocalPlayer():GetShootPos();
local vForward = LocalPlayer():GetAimVector();
local tr = {};
tr.start = vStart;
tr.endpos = vStart + (vForward2048);
tr.filter = LocalPlayer();
tr = util.TraceLine(tr);
local ent = ents.Create(“prop_physics”);
LocalPlayer().GhostProp = ent;
if ValidEntity(LocalPlayer().GhostProp) then
local vStart = LocalPlayer():GetShootPos();
local vForward = LocalPlayer():GetAimVector();
local tr = {};
tr.start = vStart;
tr.endpos = vStart + (vForward
tr.filter = LocalPlayer();
tr = util.TraceLine(tr);
local vFlushPoint = tr.HitPos - (tr.HitNormal * 512);
vFlushPoint = ent:NearestPoint(vFlushPoint);
vFlushPoint = ent:GetPos() - vFlushPoint;
vFlushPoint = tr.HitPos + vFlushPoint;

I do not want to spawn props through a menu. The plan is to spawn prop through a prop spawner. So I select the prop in a menu and then wherever I look I see a ghost prop which doesnt intersects another prop or the world. Then when I left click it spawns the prop at the ghost props location.

It is easy when the prop is a cube as all faces are the same distance away from the prop origin. When the prop is not a cube (most props), then it is more difficult as it depends on which face I’m looking at.

I gave you the code you need to use to make it not collide, it doesn’t matter whether or not you’re using a menu, my code was just an example.

That kinda works drew, as it doesnt collide/intersect with other props and the world, but I can move my crosshair anywhere as long as i stays within the ghost prop face that is touching the object. arghh It is too difficult to explain. I’ll take a video quick.

[editline]7th January 2011[/editline]

My other post was aimed towards -TB-

Oh, lol.

Ah, I see what you mean, hmm you may need to tweak it a little bit, or the players can just move the prop, or are you planning to remove physgun completely to stop prop blocking and stuff?

The physgun will stay although it pretty much isnt needed with my recent additions. Im mainly trying to get props from spawning inside of eachother or spawning way off the prop Im looking at like what happens with the fences. I wish I could tweak your code some more but the function that makes it not collide is the same function that makes it not work like I want it to. haha It is the NearestPoint function.

Oh, I’ve never been very good with all that stuff. That code I got from something we were planning for the original RP but never implemented. I think it was copied from sandbox though.

Ive looked through that gmod tool forever now and I dont believe it will work. It is basing a lot of the positions off of that original stationary prop that is initially clicked on.

So since that wont work, does anyone have any idea on how I can do this?