getting which surface of prop does player look

I am working on a build tool, what I’m trying to do is getting where the player is looking at on the prop

Here, I tried to simulate it;

https://puu.sh/yi7Es/943e0db496.png

I’ve tryed dotproduct like this;



--I just copied this function from wiki since I couldn't really understand the logic of dotproduct.
function isLookingAt(targetVec)
 	return ply:GetAimVector():DotProduct( ( targetVec - ply:GetPos() + Vector( 70 ) ):GetNormalized() ) < 0.50
end

--this part is in a draw hook
local posses = {
   pos+up*20,
   pos+right*20,
   pos+forward*20
}
--I know that this would detect only the up*20, right*20, forward*20 vectors but it doesnt even do it.

for i=1,#posses,1 do 
	if isLookingAt(posses*) then
		render.DrawWireframeSphere(posses*,5,8,8,color_white,false)
	end
end


I might be misunderstanding you, but you could try using

Player:GetEyeTrace and checking the HitPos.



print( LocalPlayer():GetEyeTrace().HitPos )


Actually, you probably meant you wanted a rectangle like the one in the picture. oops

Yeah I thought that would work but how would you know which surface that HitPos equivalent to?

This may be of interest:

util.IntersectRayWithOBB

I’ll try experimenting with it and provide example code if I can. Never used it myself.

I look forward to your reply

[lua]
local ply = LocalPlayer()
local tr = ply:GetEyeTrace()
local ent = tr.Entity

– you may have to change (GetRight, GetUp…) depending on the prop
local ang = ent:GetForward():Angle()

local hitpos, normal, fraction = util.IntersectRayWithOBB(ply:GetShootPos(), ply:GetAimVector() * 16384, ent:GetPos(), ang, ent:OBBMins(), ent:OBBMaxs())
if (hitpos) then
local center = ent:LocalToWorld(ent:OBBCenter())
debugoverlay.Line(center, center + normal * 512, 5, Color(255, 0, 0), true)
end
debugoverlay.Line(tr.StartPos, tr.HitPos, 5, color_white, true)
debugoverlay.BoxAngles(ent:GetPos(), ent:OBBMins(), ent:OBBMaxs(), ent:GetAngles(), 5, color_white)
[/lua]

Quick test gave this, although it doesn’t work perfectly for every prop for some reason. Also type “developer 1” in your console to see the debugoverlay

As you mentioned, it doesnt work perfectly but thank you so much. The situation is enough complex to give up… :hammered: