-
Notifications
You must be signed in to change notification settings - Fork 0
Target prediction
NOTE: Target prediction isn't perfect, currently its' primary issue is that there is no way to automatically determine if the target only moves with momentum (Like players), trust me, I tried for like 2-3 days and only ended up with rage at how arcane and broken Doom physics are. So you must mark your momentum-only actors with the VelocityMonster variable if they aren't based on KAI_Actor. Or give them the +MOVESWITHVELOCITY flag.
NPCs made using the KAI library have the ability to lead their shots when firing projectile attacks, allowing them to shoot at where their target will likely be at by the time the projectile arrives, instead of dumb firing at where their target was at the moment of shooting. This allows them to be a lot better at attacking distant and/or fast targets, instead of always missing like normal monsters do. They have two methods to do this which this page overviews.
Let's start off simple(-ish), the primary reason that target prediction is required and is noteworthy is that by default monsters do not actually move. While players move by actually applying momentum to themselves like you'd expect, monsters move by calling TryMove, which moves them from point A to B by actually teleporting them a set amount of map units away, the distance of which is what the ubiquitous speed property is for. GZDoom has rendering interpolation applied to these teleport steps, to smooth out the movement of monsters, which is why it's not normally noticeable.
As you can see, when the interpolation is turned off, it becomes obvious that monsters actually move by teleporting.
This requires the KAI library to need some really specialized handling to be able to actually make NPCs fire at teleporting monsters, which is how the majority of all Doom monsters (Including other modded ones) move. Hence why it's so noteworthy.
This is the simplest way to perform target prediction on your NPCs, and is shared by all KAI NPCs. VelInterceptEx(), like the name implies, is a more advanced version of the native VelIntercept() function. Unlike VelIntercept(), this function can also account for the movement of normal monsters like explained above. Including being able to account for monsters that are calling TryMove() while also being thrust, such as when a monster is hit by an explosion but still trying to move towards its' target. VelInterceptEx() should pretty much always be used in place of VelIntercept() if you want your non-vehicle NPCs to fire ahead of their targets' trajectory, but don't want to use the more sophisticated aiming ahead. It also includes a field of view check, that is used to prevent oddities like monsters firing right behind them.
In addition to VelInterceptEx(). KAI NPCs can also shoot ahead of their target by actually aiming ahead, instead of altering the velocity of their projectiles post-fire. NPCs will move ahead of their targets' trajectory based on where the target will be by the time the projectile attack arrives. Similar to how real world weapons like anti-air guns and CIWS systems work. No VelIntercept() hacks needed. Like the simpler VelInterceptEx() method, this also works with monsters experiencing knockback.
Target prediction enabled:
Yellow line: Where the turret is currently aiming. White line: Where the turret wants to aim.
As you can see, the turret is moving ahead of the Pinky it's tracking, while also still being able to keep track of it after each shell knocks it back. As evidenced by the yellow line bouncing with every impact of the shells.
Target prediction disabled:
- Home
- Features
- Classes
- Functions
- Guides