Space Engineers

Space Engineers

[Obsolete] Cruise Missile Script Mk2
Alysius  [developer] 5 Sep, 2015 @ 6:21am
Cruise Missile Script Mk2 Documentation
Script to control your cruise missile. Easy deployment with automatic detection of gyroscope and thrusters orientation. This script has been updated with additional feature to point side thrusters at natural gravity.

This is a vanilla script. No mods are required.


Features

1) Drift Function - This setting is used when your missile has no side thrusters. The drift function will perform over-steering to compensate for the drift. Can be activated by setting "boolDrift" to true.

2) Beam Riding Function - This allows the use of Turret AI's 800m auto aiming to guide the missile to the target.

3) Lead Target Function - By default the missile will try to lead the target, to correct the tail chasing problem.

4) Orientation Auto Detection - All gyroscopes, thrusters and beam riding turret can be mounted in any orientation. The script will auto detect the appropriate orientation and configure it accordingly.

5) Real Time Tracking - The target coordinates can be continuously updated while the missile is in flight, to change its flight course and aimed point on the fly. Refer to Targeting Procedures for more information.

6) Natural Gravity Dampener - Automatically spins the missile to face the thrusters against natural gravity. In this way, you can have thrusters on only one side, saving cost. To activate this, set "boolNaturalDampener" to true.


Dispatch Mode

Dispatch Mode is used for multiple missile configuration, where missiles are duplicated and blueprinted with the same set of names. Script will disengage missile from grid via Merge Block or Rotor Detech first before initializing and referencing the blocks.

Additionally, script will listen on CMD's Public Title for the name of the actual Text Panel to use for getting target coordinates. this allows selection of which Text Panel to use for targeting information (Different Text Panel containing different target information).

See Dispatch Mode video and demonstration world for more information.


Notes

- If Drift Function is used and your vectorPointMid is far off from center of mass, use "midToCenterOfMassDist" to compensate. See below or screenshot for more information.


Demo Worlds And Other Links

Two demo world setups to show how the script can be used:
https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=460236584
https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=524585088


Required Setup

- A reference block named V_MID in the middle.
- A reference block named V_FRONT in front of V_MID.
- A reference block named V_TOP on top of V_MID. Latest update: If left blank, it will randomly select a top point.
- At least one gyroscope on the ship. You can save it under group named GYROS if you want script to use specific set of gyroscopes, otherwise group its optional.
- At least one thruster facing backward relative to the ship. If no such thrusters are found, script will not activate any thrusters. Manual activation will be required in this case.
- A Text Panel named CMD for inputing targeting command.
- (Required if using natural gravity dampening feature) A remote control named "LREMOTE".
- A reference block named V_DAMPENER positioned such that the direction from V_MID to V_DAMPENER is the same direction the side thrusters is going to face, towards natural gravity. Set "boolNaturalDampener" to true to use this feature.
- (Optional, If you use beam riding feature) A Turret block (Missile, Gattling, Camera Turret mods) named "BEAM" to be used for beam riding. The turret will auto aim at the target while the missile will follow its aim.
- (Optional, If you use sensor lock on feature) A sensor named "LSENSOR" to be used for sensor lock on mode. When the sensor detects a target, it will ignore all current mode and chase that target instead.


Additional Setup For Dispatch Mode

- A set of Targeting Text Panels with unique names of your choice, for input targeting command. The original CMD Text Panel's Public Title will instead be used to select the required target by inputting one of the Targeting Text Panel's name (e.g. You have CMD_TARGET_1 and CMD_TARGET_2 being updated with target coordinates by other scripts. To make missile use CMD_TARGET_2 for coordinates, set Public Title of CMD to the string: CMD_TARGET_2).
- A group of Merge Blocks, Rotors or Advanced Rotors named DISPATCH (Can be a group or blocks of this same name). This group can be a mix and match of Merge Blocks, Rotors or Advanced Rotors. When the missile received targeting command from the specified Targeting Text Panel, it will separate itself from the ship grid using the Merge Block, Rotor or Advanced Rotor within the DISPATCH group that is the closest to the programmable block running this script.

For Dispatch Mode, you can set the Private Title of CMD to a one time command that will be executed ONCE after the missile have initialized.

For Target Selection mentioned above (Populating CMD's Public Title with targeting Text Panel name), you can use Target Selection Script found at:
https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=559331737


Targeting Procedures

Enter targeting information into the CMD Text Panel's Public Title field (If Dispatch Mode is used, this should be the Targeting Text Panel). The format is:

[T:<X>:<Y>:<Z>]

Where X, Y and Z is the coordinates. You can continuously write [T:<X>:<Y>:<Z>] to the CMD Text Panel to have the missile update its flight course and aimed point on the fly.

You can also use the Beam Riding feature by entering the command:

-or- [B,W:<X1>:<Y1>:<Z1>,W:<X2>:<Y2>:<Z2>,W:<X3>:<Y3>:<Z3>]

Where "B" specifies that beam riding will be used and "W" is an optional sequence of waypoints to follow before switching to beam riding. Beam riding means the Turret will automatically aim at a target and the script will home according to the Turret's aim.

Note: You cannot use "T" and "B" together. Specifying "T" and "B" together will cause the script to ignore "T" (final target point) if there is a "BEAM" detected.

List of example commands:

[T:10:10:10] - Missile homes at target [10,10,10].
[T:10:10:10,W:1:1:1,W:2:2:2] - Missile travels to waypoint [1,1,1] then to [2,2,2] before homing at final target [10,10,10].
- Missile start off in beam riding mode.
[B,W:1:1:1,W:2:2:2] - Missile travels to waypoint [1,1,1] then to [2,2,2] before switching to beam riding mode.
[BX,W:1:1:1,W:2:2:2] - Missile travels to waypoint [1,1,1] then to [2,2,2] before switching to beam riding mode. If along the way the turret aims at some target, it switches to beam riding.
[BW,W:1:1:1,W:2:2:2] - Missile circles about waypoint [1,1,1] and [2,2,2]. If anytime the turret aims at some target, it switches to beam riding mode.


Sensor Lock On

You can specify a sensor using strLockOnSensor to use for sensor lock on mode. When the sensor detects a target, it will ignore all current modes and chase that target.


Unique Command Locking

If you specify a number in front of the command:

100[T:10:10:10]

The script will only read the command once until the number "100" is changed to a different number.
To allow the script to read the next command again, you will specify 101[T:10:10:10] and so on.


Special Settings

boolDrift - Can be set to true to force over-steering. This is used to compensate for the lack of side thrusters, if your missile design is as such. (def: false)
boolLeadTarget - Can be set to true for script to lead the target. The script will calculate the interception point and aim there instead of the current target position. (def: true)
boolDispatchMode - Can be set to true to enable dispatch mode. (def: false)
boolNoConsumeCommand - Can be set to true to prevent script from clearing the Public Title of the command Text Panel after reading the command. (def: false)
defaultLaunchSeconds - The default launch time in seconds if not specified when entering command. (def: 1)
defaultWaypointDistCutoff - The default waypoint distance in metres to consider waypoint reached if not specified in when entering command. (def: 500)
midToCenterOfMassDist - How much distance in metres the center of mass is in front of the vectorMid used by the missile. (def: 0)
driftVectorReduction - For Drift mode only. Larger value results in smaller drift, smaller value results in more aggressive drifting. Do not reduce to less than 1. (def: 1.5)
oneTimeCommand - Dispatch Mode only. The one time command to be injected during dispatch mode initialization. Must start and end with square brackets "[" and "]"
boolNoConsumeCommand - Can be set to true to prevent script from clearing the Public Title of the command Text Panel after reading the command. (def: false)
boolNaturalDampener - Can be set to true to use Natural Gravity Dampener feature.


Runtime Parameters

List of values (Set via Public Title of command Text Panel. All values are case sensitive):

[<CMD1>:<PARAMS1>,<CMD2>:<PARAMS2>,<CMD3>:<PARAMS3>]

All the possible CMD is listed below:

1) T (e.g. [T:10:20:30])
> [Decimal:Decimal:Decimal] = The coordinates of the final target point. Exclusive with B, BX and BW.

2) W (e.g. [W:10:20:30])
> [Decimal:Decimal:Decimal] = Waypoint information. Specify them in sequence for multiple waypoints.

3) B (e.g. or [B:<Turret Name>])
> (Optional) [Turret Name] = Use Beam Riding mode. Default Turrent name is BEAM. You can change it by specifying the new Turret name.

4) BX (e.g. [BX] or [BX:<Turret Name>])
> (Optional) [Turret Name] = Use Beam Riding mode and will switch to beam riding if turrent aims at some target while missile is traversing waypoint.

5) BW (e.g. [BW] or [BW:<Turret Name>])
> (Optional) [Turret Name] = Use Beam Riding mode. Missile will cycle about specified waypoints (By "W" command) and will switch to beam riding if turrent aims at some target while missile is traversing waypoint.

6) D (e.g. [D] or [D:TRUE])
> (Optional) [TRUE,FALSE] = Whether missile should drift to compensate for the lack of side thrusters.

7) P (e.g.

or [P:TRUE])
> (Optional) [TRUE,FALSE] = Whether missile should lead the target, by aiming at the calculated intercept point instead of the current target position.

8) L (e.g. [L:3])
[Decimal] = Missile will idle for 3 seconds before making first move. This is for missile launch to clear launch pad.

9) C (e.g. [C:250])
> [Decimal] = How close to the waypoint in metres before missile considers waypoint is reached. If set to 0, script will switch waypoint when missile flew past (waypoint is behind with respect to last waypoint) the waypoint.

10) E (e.g. [E:TimerBlock1:TriggerNow])
> [BlockName:ActionName] = The block and action to trigger when missile is homing to final target or is currently in beam riding mode and has already detected an enemy.

11) F (e.g. [F:TimerBlock1:TriggerNow])
> [BlockName:ActionName] = The block and action to trigger when missile launched.

12) RSL (e.g. [RSL:1:5])
> [Decimal:Decimal] = The missile will launch and travel straight ahead for a time period before turning towards target. A random amount of time is selected from "Min" to "Max". The values are specified in seconds.

13) RSD (e.g. [RSD:1:5])
> [Decimal:Decimal] = The missile will stay attached and not move for a time period before launching. A random amount of time is selected from "Min" to "Max". The values are specified in seconds.

14) ACTB (e.g. [ACTB:Warhead:Detonate])
> [BlockName:ActionName] Triggers the specified action on the block.

15) ACTG (e.g. [ACTG:THRUSTERS:OnOff_Off])
> [GroupName:ActionName] Triggers the specified action for all blocks in the group.

16) SPIN (e.g. [SPIN:30])
> (Optional) [Integer] Spins the missile by the RPM specified. If no RPM specified, it will spin at maximum speed.

17) CUT (e.g. [CUT])
> Blocks the script from receiving any further commands. Script will continue to operate based on last command received.

18) TERM (e.g. [TERM])
> Instantly terminates the missile script. Missile will drift through space according to the last momentum.

Last edited by Alysius; 15 Dec, 2015 @ 1:56am