• Find in Cone Lua
    4 replies, posted
Hello, I'm currently working on a gamemode in which a flashlight is a key element. The flashlight is used as a weapon against the enemy if the target is within a certain distance of the player whose light is on. To find the entity while the light is on, I do: [CODE] if self.Owner:FlashlightIsOn() then for k,v in pairs(ents.FindInCone(self.Owner:EyePos(),self.Owner:GetAimVector(),100,30)) do etc. end end[/CODE] This would be satisfactory, however the cone will of course go through walls, which is an issue. I had also used self.Owner:GetEyeTrace().Entity however this means the player has to be aiming directly at the target when I'd prefer it works as a cone, and that won't work either. I'm looking to see if anybody has any suggestions as to how else I could find entities in a cone without it being able to pass through walls. Essentially a way to do ent.GetEyeTrace() but modified to include every angle within a 30 degrees cone of the trace. Perhaps a combination of both where I continue with the FindInCone but make it conditional that the player's trace within this range doesn't hit the world? I'm sort of out of ideas. Any ideas, suggestions or solutions would be appreciated Thanks, and Happy Holidays.
Zombie Survival has a boss called Shade, which can be damaged only by flashlight - I recommend you go look at that I don't exactly know where you'd want to look but here may be a start: [url]https://github.com/JetBoom/zombiesurvival/blob/master/gamemodes/zombiesurvival/gamemode/zombieclasses/boss_shade.lua[/url]
[QUOTE=NiandraLades;46791002]Zombie Survival has a boss called Shade, which can be damaged only by flashlight - I recommend you go look at that I don't exactly know where you'd want to look but here may be a start: [url]https://github.com/JetBoom/zombiesurvival/blob/master/gamemodes/zombiesurvival/gamemode/zombieclasses/boss_shade.lua[/url][/QUOTE] [url]https://github.com/JetBoom/zombiesurvival/blob/master/gamemodes/zombiesurvival/entities/entities/status_shadeambience/init.lua[/url] In the think hook they use LightVisible which simply checks if there's a clear line of site. Then they get the dot product of a position at the flashlight owner and the shade. They take the return value of [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Vector/Dot]Vector:Dot[/url] and check to see if it's >= 0.85 which effectively checks within a cone. They then do a bit of math which looks like it will cause more damage the closer the shade is to the player and the closer the shade is to the center of the cone. As far as I understand your current problem you could just do a trace to see if there is a clear line of site from the player's eyes to the target THEN either use ents.FindInCone or do a similar check using Vector:Dot.
Thanks again for the help, I'll try those methods out as well.
If you get the list of entities in the cone, you can do an unconditional trace (Because you can assume that the entity is inside of the player's flashlight cone) with a filter and see if it hits a wall. If it does, well you have a hit a wall and the player cannot see the entity.
Sorry, you need to Log In to post a reply to this thread.