What trace code does sandbox use for when spawning a prop?
Right now I use, [CODE]local tr = player:GetEyeTrace()[/CODE] and pass it to the spawn code but right now It spawns the prop at a bloody stupid location and half into the ground.
Any help? thank you.
[lua]
local min = ent:OBBMins()
ent:SetPos( trace.HitPos - trace.HitNormal * min.z )
[/lua]
You have to offset the prop's Z by it's size. For many props the "center" is the middle bone, and when you try to place a prop it will use this bone as a guide for where the prop should be in relation to the vector
I tired it and it spawned closer to me but still not right and still half into the floor.
[code]tr = player:GetEyeTrace()
local min = ent:OBBMins()
ent:SetPos(tr.HitPos - tr.HitNormal * min.z )[/code]
I think the issue is with the Eye trace for some unusual reason.
It looks like OBBMins() and other bounding box functions will return (0,0,0) until the entity is actually spawned. (Entity:Spawn()) Not sure whether that's a factor here or not.
That worked thank you but still the EyeTrace() seems to be not picking up the correct location, it goes left of the aimed spot, any ideas?
Fixed, using :GetEyeTraceNoCursor() made it function appropriately, Thank you both for the assistance.
Sorry, you need to Log In to post a reply to this thread.