Wednesday, December 5, 2012

Turrets

I want to create a turret manager that will manage all of the turrets attached to a capital ship.  Before I tackle this feature, I do want to create another model to represent a destroyed turret and implement a procedure to change models.  Here's a picture of the current Colonial turret:


I want to create a destroyed version of this turret.  It really shouldn't be too hard to create a destroyed version; however, we'll see if that's a true statement shortly.

As for the turret manager, this script should work as an intermediate script between the turret control (equivalent to the flight control script for a fighter) and the capital ship's AI script.  As intermediate script, I am hoping that it maintains a higher level of performance on older computers by breaking up the turret's AI routines from mechanical implementation of those decisions.  In addition, consolidating those scripts into an intermediate script will allow the game to control turrets as a single unit, when possible.  Passing the AI data directly to the turret control script is more likely to see turrets acting as individual units. 

The turret manager should accept a target from the AI routine as it's primary IO function.  Based on the received target, the manager will calculate the movement of each turret and will decide on whether or not to fire weapons at set intervals (FixedUpdate).  Basically, it will have the movement and firing routines of the Fighter AI's script.  It will not possess the full target selection script as a default.  If a turret absolutely cannot obtain a sufficient firing angle, the turret manager will be able to find an alternative target for each turret. 

Here's the process flow for the manager:

Main Loop:
Get target data.
Rotate turret to target
Fire weapons if the target is within 15 degrees of target
If it reaches the maximum rotation threshold and cannot obtain a fire solution, then place the turret into automated mode.
Loop to Main Loop

Automated mode loop:
Find the best target within threshold range; if there is no target, keep the main target as a target
Fire weapons if the target is within 15 degrees of target
If the main target is within 5 degrees of the threshold range, switch target to main target and take the turret out of automated.
Loop to Automated mode loop

Special note: Get target data doesn't happen within the Update() procedure; it is passed directly to the turret manager.

To make this loop happen, I need the following variables:

vMainTarget : Transform
vTurretList : List<TurretData>

TurretData will contain the following fields:

vTurret : Transform
vTurretControl : TurretControl
vFireControl : FireControl
vTarget : Transform

This should give me a decent starting point to start the process for finishing turrets...

1 comment:

  1. I created a destroyed turret. I don't really like how it looks; however, it's better than nothing. I'll incorporate it into the turret setup later. I'll have to change the destruction routine... That'll come later.

    I decided to utilize each turret individually; however, it will be done through the turret manager. I still want the turret control to handle the mechanical movement. The only thing that the main AI will pass to the manager is the main mission target.

    The basic outline is to:

    Find the target
    Rotate the turret
    Fire the turret

    I will use the fighter AI routine to provide the basic template to make this happen. The major differences will be a simplification of the target selection and the lack of movement just rotation.

    Targetting will default to the mission target if it is within the turret's firing arc. Otherwise, it will take the closest target within it's firing arc.

    For rotation, that part is already done and operational in the turret control. The trick is to calculate the rotation angles. The fighter AI will provide the template for this.

    ReplyDelete