Skelitten Games

Code Structure Explained

Understand the logic behind the interception turret, allowing you to modify the code.

Begin Play - AC_InterceptionComponent

The AC_Interception component tries to read multiple settings from the BP_InterceptionTurret on Begin Play:

  • Average Fire Location (the average location of all fire locations of the turret)
  • Projectile Speed and Gravity Scale (required for interception algorithm)
  • Rotation Range (calculations will only run while the target is within this range)
  • Maximum Time to Intercept (any interception taking longer than this duration will be marked as invalid)
  • Interception Method (choose an interception algorithm)
  • Newtonian Iterations (required when using Newtons Method)

If you are using your own turret actor, you need to update the "Initialize Component" function on the AC_Interception component. The component cannot calculate an interception path without receiving this data.

AC_InterceptionComponent - InitializeComponent: The component can only read the required data if its owner is (a child) of the BP_InterceptionTurret.

Begin Play - BP_InterceptionTurret

The turret's Begin Play event is quite simple:

  • The initial target is forwarded to the AC_InterceptionComponent (and set as the current target).
  • An array of all fire locations is created.

If you need to add or remove fire locations, simply add or remove inputs of the "Make Array" node and connect all fire locations (Info: A fire location is an arrow component attached at the tip of a barrel where the bullet should spawn).

The turret will cycle through all fire locations while firing.

Tick - AC_InterceptionComponent

The following logic is running on the tick event of this component:

  1. Try and read the current location of the target. This of course only works while a valid target reference is set.

    If the target goes from being to valid to invalid, the component will reset its current calculation status and variables. It will also call the "Find New Target" function on the BP_InterceptionTurret.
  2. If the target's location could be retrieved, use it to calculate the target's speed and acceleration (if required). To do this, the component needs to know the previous location and velocity of the target. Therefore, this calculation takes 2-3 ticks (depending on if acceleration should also be calculated or not).
  3. Provided that the velocity and acceleration calculations are complete and that the target is withing range, the component will calculate an interception velocity. This is the velocity that should be applied to a projectile to intercept the target.

    Note: Unless a valid interception velocity could be calculated, the interception velocity will always be set to its owner's forward vector. This is so that the turret can always rotate towards this vector. If no interception is possible, the turret will simply return to its default orientation.

Important Note

If you have any further questions, ideas, encountered an issue, or need help adjusting any of the provided blueprints, please don't hesitate to send me a message on the support discord server.

Search documentation

Type to search all documentation.

Choose your engine