Interkarma / daggerfall-unity

Open source recreation of Daggerfall in the Unity engine
http://www.dfworkshop.net
MIT License
2.74k stars 332 forks source link

Fix enemies sometimes hearing thru walls #2681

Closed petchema closed 1 month ago

petchema commented 3 months ago

Previous code checked that the first obstacle between an enemy and its target was an object tagged "static" to determine if the enemy could hear the target (followed by a distance check). In some cases that allowed enemies to hear targets when they shouldn't (other static tagged objects along the "line of hearing" not checked), leading to enemies facing walls or still chasing enemies thru walls when you encounter them.

This PR first checks for distance to target (like CanSeeTarget() does), then checks if they're no object tagged static inbetween the enemy and its target. As an optimization, only objects on layer "Default" are considered, and Physics.RaycastNonAlloc() API is used to lower memory allocations.

Forums: https://forums.dfworkshop.net/viewtopic.php?t=6759

petchema commented 1 month ago

As it occurred to me after the fact, a more efficient way to solve this issue would be to dedicate a layer to static objects, so a simple raycast with a layer mask would be sufficient, instead of retrieving hits and checking individual tags...

KABoissonneault commented 1 month ago

Yeah probably. I'm just not sure about the risk, when it comes to modded dungeon blocks. I'm not sure how much we can expect existing mods that have objects with the static tag but default layer, expecting them to block sound