Dot Product VS Blueprint Interface method
Comparing methods to get environment critters to react to sound and proximity bringing a sense of realism.
UNREAL AUDIO
Chris Chen
7/16/20252 min read
If you haven't seen my video about getting environment critters to react to your presence, you can check that out in this video.
In short, I created a collision sphere that detects projectiles and characters using BPIs. This approach is efficient because it avoids the need to cast from various characters, projectiles, or anything else that might come into contact with our critter. Instead, we can simply use a BPI and run a check. If there were hundreds of critters around a biome, that kind of casting could get expensive. I wrote a blueprint that runs this check with a timer to reset the sound so that it chirps again when it's "safe."
The problem with this method, however, is that projectiles can go in the same direction as our critters, but go over and miss the sphere—colliding with nothing. I could either make the sphere massive and try to cover that, or I could use the Dot Product, which enables us to shoot in the general direction of our critter and stop it from singing.
Here is the blueprint running the BPI checks. Keep in mind I've added the BPIs to the projectiles and BP_Character. Not having to cast is awesome.



I've done some math here to get the Vector from PlayerToCritter. It's simply a matter of subtracting the player location from the critter location then running the PlayerToCritter and PlayerForward through the dot. I ran another check for distance to get the critter to stop when in close proximity. As far as projectile interaction goes (using Dot), it's just running a check to see if the weapon is being fired and aimed in that general direction as you can see by the dot product being less than 0.5
In this GIF, you can see that when I'm shooting towards the critter, the rest of the code is called, which then runs a random clamped delay and goes back to retrigger the Play function. The custom event timer is running at 0.1 instead of every frame like a tick would, saving memory.


And here you can see that when aiming in the general direction, the stop is being printed on screen. Aiming and shooting at a different angle does not call the Stop function as the dot is greater than 0.5. Though could use some tweaking as the angle seems to be quite wide.


Running a MemReport shows that BP_Frog (using the BPI) is using a little less memory than BP_Bird (using the dot product).
This can be found in your project profiling folder