Home   Help Search Login Register  

Author Topic: Guided missile script question  (Read 2236 times)

0 Members and 1 Guest are viewing this topic.

IliekBIGboom

  • Guest
Guided missile script question
« on: 24 Aug 2002, 15:45:31 »
Greetings,

Hope you dont mind me starting off with a question about Sefe's guided missile script.

By chance i found the script posted on the official ofp forums, with little information on how to set it up.
So i got the script and would like to use the addon Tomahawkmissile as the missile being generated by the script.
(being launched of a cruiser of shore)

the idea i have is that the script is called when an AI or a player points a Laser at a target.
Is this possible and how do i actually set this up?

Great thanks in advance.

ps: i hope Ofpec will be up soon again

**********************************************
script i found on official ofp forum's

;Guided missile script v1.1
;by SEFE

_Target = _this Select 0
_MissileType = _this Select 1
_MissilePos = _this Select 2
_MissileDir = _this Select 3
_MissileElev = _this Select 4
_LockAngle = _this Select 5
_SAM = _this Select 6
_Internal = _this Select 7

SetAccTime 1

_LockedOn = TRUE

;Create missile
_Missile = _MissileType CamCreate [_MissilePos Select 0, _MissilePos Select 1, 1000]
_Missile SetDir _MissileDir

;Create tracking object (needed to calculate the missile's barometric altitude - also used in terrain following mode) - GetPos returns the altitude AGL but SetPos expects the barometric altitude
_Tracker = "PipeBomb" CamCreate [_MissilePos Select 0, _MissilePos Select 1, 0]

~0.2

;Calculate initial missile altitude
_InitialMisAlt = (_MissilePos Select 2)
_Tracker SetPos [_MissilePos Select 0, _MissilePos Select 1, 0]
_MissileAlt = _InitialMisAlt - ((GetPos _Tracker) Select 2)

;Set initial missile position
_Missile SetPos [_MissilePos Select 0, _MissilePos Select 1, _MissileAlt]

;Get initial target altitude
_TargetPos = GetPos _Target
_Tracker SetPos [_TargetPos Select 0, _TargetPos Select 1, 0]
_TargetAlt = (_TargetPos Select 2) - ((GetPos _Tracker) Select 2)

;Get the missile's initial distance to target
_DistanceToTarget = _Missile Distance _Target
_DeltaTargDist = 0

;Init the missile's lock angle
_LockAngle = _LockAngle / 2

;Init the missile's vertical angle
? _MissileElev > 70 : _MissileElev = 70
? _MissileElev < -70 : _MissileElev = -70

;View through missile camera
? _Internal : _Missile CameraEffect["INTERNAL", "BACK"]

#CalculateTrajectory
;Get the positions and altitudes of the target and the missile
_MissilePos = GetPos _Missile
_TargetPos = GetPos _Target

_Tracker SetPos [_MissilePos Select 0, _MissilePos Select 1, 0]
_MissileAlt = (_MissilePos Select 2) - ((GetPos _Tracker) Select 2)

_Tracker SetPos [_TargetPos Select 0, _TargetPos Select 1, 0]
_OldTargetAlt = _TargetAlt
_TargetAlt = (_TargetPos Select 2) - ((GetPos _Tracker) Select 2)

;Get the missile speed
_MissileSpeed = Speed _Missile

;Get the missile's direction
_MissileDir = GetDir _Missile

;Get the missile's distance to the target
;_OldDistanceToTarget = _DistanceToTarget
;_DistanceToTarget = _Missile Distance _Target
;_DeltaTargDist = _DistanceToTarget - _OldDistanceToTarget

;Get the missile's horizontal angle to the target (using trigonometry)
_DeltaX = (_TargetPos Select 0) - (_MissilePos Select 0)
_DeltaY = (_TargetPos Select 1) - (_MissilePos Select 1)
? (_DeltaY == 0) && (_DeltaX >= 0) : _TargetAngle = 90
? (_DeltaY == 0) && (_DeltaX < 0) : _TargetAngle = 270
? _DeltaY > 0 : _TargetAngle = ATan (_DeltaX / _DeltaY)
? _DeltaY < 0 : _TargetAngle = ATan (_DeltaX / _DeltaY) + 180
? _TargetAngle < 0 : _TargetAngle = _TargetAngle + 360

;If it is an AA missile, we have to guide it to the interception point, not to the target itself (using even more trigonometry)
? not _SAM : Goto "NoDeflectionShooting"

;Calculate the deflection angle and add it to the target angle
? _MissileSpeed != 0 : _TargetAngle = _TargetAngle + ASin ((Sin ((GetDir _Target) - _TargetAngle)) * (Speed _Target) / _MissileSpeed)

#NoDeflectionShooting

;Get the horizontal angle between the missile's direction and the target
_RelTargetAngle = _TargetAngle - _MissileDir
? _RelTargetAngle > 180 : _RelTargetAngle = _RelTargetAngle - 360
? _RelTargetAngle < -180 : _RelTargetAngle = 360 - _RelTargetAngle

;Calculate the missiles horizontal angle change
_HorzDelta = _RelTargetAngle
? (_HorzDelta > 4) && _SAM : _HorzDelta = 4
? (_HorzDelta < -4) && _SAM : _HorzDelta = -4
? (_HorzDelta > 2) && not _SAM : _HorzDelta = 2
? (_HorzDelta < -2) && not _SAM : _HorzDelta = -2

;Check if the missile has lost it's horizontal lock
? (Abs _RelTargetAngle) > _LockAngle : _HorzDelta = 0; _LockedOn = FALSE

;Calculate the missile's new direction
_NewMissileDir = (GetDir _Missile) + _HorzDelta


;Roughly calculate the missile's horizontal position in the next cycle (needed to evade obstacles on the ground)
_MissileVector = _DeltaTargDist
? _MissileVector > _DistanceToTarget : _MissileVector = _DistanceToTarget
_NextMissileX = (_MissilePos Select 0) + (Sin _NewMissileDir) * _MissileVector
_NextMissileY = (_MissilePos Select 1) + (Cos _NewMissileDir) * _MissileVector

;Calculate the ground elevation at the missile's next horizontal position
_Tracker SetPos [_NextMissileX, _NextMissileY, 0]
_NextGroundElev = -((GetPos _Tracker) Select 2)


;Define vertical flight path (guess... using trigonometry)

;The flight path is calculated differently for AA and AG missiles
? not _SAM : Goto "CalcAGMissile"

;Get the missile's vertical flight angle to the target
_DeltaZ = (_TargetAlt - _MissileAlt) + 3

;An AA missile will try to reach the target altitude as quickly as possible
? (_DistanceToTarget == 0) && (_DeltaZ >= 0) : _ClimbAngle = 90
? (_DistanceToTarget == 0) && (_DeltaZ < 0) : _ClimbAngle = -90
? _DistanceToTarget != 0 : _ClimbAngle = ATan (_DeltaZ / _DistanceToTarget)
? (_DeltaZ > 40) : _ClimbAngle = 30
? (_DeltaZ > 60) : _ClimbAngle = 45
? (_DeltaZ > 80) : _ClimbAngle = 60
? (_DeltaZ < -40) : _ClimbAngle = -30
? (_DeltaZ < -60) : _ClimbAngle = -45
? (_DeltaZ < -80) : _ClimbAngle = -60

;Calculate vertical deflection
? _DeltaTargDist != 0 : _ClimbAngle = _ClimbAngle - (ATan ((_OldTargetAlt - _TargetAlt) / _DeltaTargDist))

;Avoid obstacles on the ground
_MinAltitude = 8
? _DistanceToTarget < 150 : _MinAltitude = 0
? (_TargetPos Select 2) < _MinAltitude : _MinAltitude = (_TargetPos Select 2)

_MinElev = -70
? _MissileVector != 0: _MinElev = ATan((_MinAltitude + _NextGroundElev - _MissileAlt) / _MissileVector)
? _ClimbAngle < _MinElev : _ClimbAngle = _MinElev

Goto "CalcVertAngle"

#CalcAGMissile

;An AG missile will follow the terrain until it's near the target
? _DistanceToTarget < ((_MissilePos Select 2) * 8) : Goto "FinalSequence"

_DeltaZ = _InitialMisAlt - (_MissilePos Select 2)
;An AG missile will try to keep it's initial height
? (_MissileVector == 0) && (_DeltaZ >= 0) : _ClimbAngle = 90
? (_MissileVector == 0) && (_DeltaZ < 0) : _ClimbAngle = -90
? _MissileVector != 0 : _ClimbAngle = ATan (_DeltaZ / _MissileVector)
? (_DeltaZ > 40) : _ClimbAngle = 30
? (_DeltaZ < -40) : _ClimbAngle = -30

;Follow terrain elevations
? _MinElev = -70
? _MissileVector != 0 : _MinElev = ATan((_InitialMisAlt + _NextGroundElev - _MissileAlt) / _MissileVector)
? _ClimbAngle < _MinElev : _ClimbAngle = _MinElev

Goto "CalcVertAngle"

#FinalSequence

_DeltaZ = (_TargetAlt - _MissileAlt) + 1

? (_DistanceToTarget == 0) && (_DeltaZ >= 0) : _ClimbAngle = 90
? (_DistanceToTarget == 0) && (_DeltaZ < 0) : _ClimbAngle = -90
? _DistanceToTarget != 0 : _ClimbAngle = ATan (_DeltaZ / _DistanceToTarget)

#CalcVertAngle

;Get the vertical angle between the missile's direction and it's vertical flight path
_RelTargetElevation = _ClimbAngle - _MissileElev
? _RelTargetElevation > 180 : _RelTargetElevation = _RelTargetElevation - 360
? _RelTargetElevation < -180 : _RelTargeElevation = 360 - _RelTargetElevation

;Calculate the missiles vertical angle change
_VertDelta = _RelTargetElevation
? _VertDelta > 4 && _SAM : _VertDelta = 4
? _VertDelta < -4 && _SAM : _VertDelta = -4
? _VertDelta > 1 && not _SAM : _VertDelta = 6
? _VertDelta < -1 && not _SAM : _VertDelta = -6

;Check if the missile has lost it's vertical lock
? (Abs _RelTargetElevation) > _LockAngle : _VertDelta = 0; _LockedOn = FALSE

;Calculate the missile's new vertical direction
_MissileElev = _MissileElev + _VertDelta
? _MissileElev > 70 : _MissileElev = 70
? _MissileElev < -70 : _MissileElev = -70


;Apply all changes to the missile's trajectory

;Change the missile's horizontal direction
_Missile SetDir _NewMissileDir

;Change the missile's altitude
_OldDistanceToTarget = _DistanceToTarget

~0.005

_MissilePos = GetPos _Missile

_DistanceToTarget = _Missile Distance _Target
_DeltaTargDist = Abs(_DistanceToTarget - _OldDistanceToTarget)
_MissileAlt = _MissileAlt + (Tan(_MissileElev) * _DeltaTargDist)

;Set the missile's new position
_Missile SetPos [_MissilePos Select 0, _MissilePos Select 1, _MissileAlt]

;Loop to next scan cycle
? (Speed _Missile > 0) : Goto "CalculateTrajectory"

;Reset cam mode
? _Internal : _Missile CameraEffect["TERMINATE", "BACK"]

;Destroy missile
CamDestroy _TrackingMissile
CamDestroy _Missile

Exit
********************************************** :o :o ;D

Big-Boss

  • Guest
Re:Guided missile script question
« Reply #1 on: 24 Aug 2002, 19:11:19 »
Hmmmmm, good question, I think that the script may need to be modified to work with the LTD(laser target designator), as the script was originally designed for an intro sequence. Maybe one of the "gurus" can help you out with that.

tai mai shu

  • Guest
Re:Guided missile script question
« Reply #2 on: 25 Aug 2002, 00:27:59 »
i have lots of problems with dat script, it seems that the missiles arent very accurate

Offline Sefe

  • OFPEC Patron
  • Former Staff
  • ****
Re:Guided missile script question
« Reply #3 on: 26 Aug 2002, 14:02:29 »
the script was originally designed for an intro sequence.

The script was inspired by a question in the old ikonboard forums. I don't remmebr if the question was about an intro sequence. But the script wasn't designed specifically for an intro sequence.

As for the accuracy of the missile: It depends on the missile type you use. If you fire upon an aircraft, you should use an anti-air missile (eg. an AA or a 9K32) as it's more agile than an anti-ground missile and thus will more likely hit the target. If you want to attack ground vehicles use an anti-ground missile. It will be less agile but have more firepower. You can also use the Tomahawk missile from the addon without modifying the script. Just put in the correct class name.

To make it fork with the laser designator you need a second script that will acquire the laser target. Once you have the laser target (which is just a special vehicle) you should be able to pass it as a target to the guided missile script.

IliekBIGboom

  • Guest
Re:Guided missile script question
« Reply #4 on: 26 Aug 2002, 23:23:15 »
Alright, thx for reply

tai mai shu

  • Guest
Re:Guided missile script question
« Reply #5 on: 27 Aug 2002, 04:12:49 »
yeah, too bad that the _nearestobj command is broken in resistance. it woulda helped a lot i think.

what you could do is make a huge trigger covering the enitre
make a gameliogic, name it gamelogic1, place it where you want hte missile to come from
battlefield area, activation anyone present repeatedly, than in condition field, erase everytihg, and put this-
"lasertarget" counttype thislist > 0
in activation, put
laseron = true
this will detect if the laser has been turned on.

make another trigger, radio alpha, repeatedly
in condition,type

this && laseron

in activation, put

[(name of the lasertarget, im not sure what it is), "maverick", getpos gamelogic1, 0, 25, 360, FALSE, (put true if you want a camera on the missile, false if you dont) "exec Guidmissile.sqs"

so when you turn on the laser, point it at target, and radio alpha, missil should be created and if theres no buildings or trees in the way, it should take out the target.