• Check if something is colliding with a prop
    4 replies, posted
I currently have [code] for k, ply in pairs(player.GetAll()) do if (ply:GetPos():Distance(ent:LocalToWorld(ent:OBBCenter())) < rad) then inside = true end end [/code] But with long props, that ends up not working, and inside is true if a player is just near it. Is there any way to accurately tell if anyone is inside/touching a prop?
Do a hull trace like this: [lua] local pos = ply:GetPos() local tracedata = {} tracedata.start = pos tracedata.endpos = pos tracedata.filter = ply tracedata.mins = ply:OBBMins() tracedata.maxs = ply:OBBMaxs() local trace = util.TraceHull( tracedata ) if trace.Entity and !trace.Entity:IsWorld() and trace.Entity:IsValid() then --They're touching something. end [/lua] I used this to check if the player was stuck. If you want to see if they're colliding rather than checking for being inside, add just a LITTLE more to the OBBMins() and OBBMaxs() of the player to check for objects just outside the bounds of the player.
[QUOTE=bobbleheadbob;43506175]Do a hull trace like this: [lua] local pos = ply:GetPos() local tracedata = {} tracedata.start = pos tracedata.endpos = pos tracedata.filter = ply tracedata.mins = ply:OBBMins() tracedata.maxs = ply:OBBMaxs() local trace = util.TraceHull( tracedata ) if trace.Entity and !trace.Entity:IsWorld() and trace.Entity:IsValid() then --They're touching something. end [/lua] I used this to check if the player was stuck. If you want to see if they're colliding rather than checking for being inside, add just a LITTLE more to the OBBMins() and OBBMaxs() of the player to check for objects just outside the bounds of the player.[/QUOTE] I changed that to [code] local inside = false local pos = ent:OBBCenter() local tracedata = {} tracedata.start = pos tracedata.endpos = pos tracedata.filter = {ply, game.GetWorld(), Entity(0)} tracedata.mins = ent:OBBMins()--*Vector(1.2,1.2,1.2) tracedata.maxs = ent:OBBMaxs()--*Vector(1.2,1.2,1.2) local trace = util.TraceHull( tracedata ) ply:ChatPrint(tostring(trace.Entity)) if trace.Entity and trace.Entity:IsPlayer() and trace.Entity:IsValid() and not trace.Entity:IsWorld() then inside = true ply:ChatPrint("You're inside!") end if inside == true then return false end [/code] and trace.Entity is always the world, no matter what. Any ideas?
If it's a SENT you can use self:SetTrigger(true) and then use the built-in ENT:StartTouch and ENT:EndTouch
[QUOTE=JetBoom;43512512]If it's a SENT you can use self:SetTrigger(true) and then use the built-in ENT:StartTouch and ENT:EndTouch[/QUOTE] It's not an SENT. I'm calling it on the prop freeze hook.
Sorry, you need to Log In to post a reply to this thread.