This is part of Math for Game Devs by Freya Holmér
Interactive Demo
7
3
0.5
Requirements Coverted to Three.js & R3F
-
5a
- Give the turret a configurable target detection range and height
- Make sure this is relative to the turret placement’s local space!
- Note: Drawing the trigger itself is harder than solving this problem mathematically, so don’t get too caught up in visualization unless you really want to!
-
5b
- Give the turret a configurable view cone target detection angle/width, so that it only detects things in front of it, within either a narrow or wide range
- Again, make sure this is relative to the local space of the turret, so that the trigger is moved and aligned along with the turret’s alignment
- Note: You don’t have to use angles or trigonometry for this, but you can if you want to!