Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Final homing
- //set Target to "nameoftarget".
- //YOU MUST MANUALLY TARGET YOUR TARGET BEFORE EXECUTING THIS PROGRAM.
- //Editable Parameters
- set explosionradius to 8.
- set iterations to 8.
- set initialguess to 15.
- set pitchangle to 15.
- Clearscreen.
- //Do Targeting
- print "Enemy heat signature acquired. Homing!!!".
- print"Missile by Peter Sharpe".
- print"Syntax updated to Kos 1.3.0.0 from 1.1.3.0".
- print"By NotUrGenre".
- //Launch Sequence
- lock throttle to 1.
- //Set up outputs
- print "Time to interception:" at (6,0).
- print "Distance to Target:" at (7,0).
- print "Steering Error:" at (8,0).
- //Take steering control, lock it to "steeringangle"
- set steeringangle to up+target:direction.
- sas off.
- lock steering to steeringangle.
- //Arm the warhead to trigger with radius of "explosionradius" + 1 frame to decouple.
- when t<explosionradius/50+0.05 or target:distance<50 then {stage. set vectordraw:show to false.}
- print "Warhead armed. Initiating homing algorithm." at (9,0).
- //Homing Algorithm, infinite loop
- set t to 10.
- until 0
- {
- set steeringangle to up+target:direction.
- set rpos to (0-1)*(target:Position).
- set rvel to (ship:velocity:surface-target:velocity:orbit).
- if target:loaded {set rvel to ship:velocity:surface-target:velocity:surface.}.
- if altitude>35000 or target:altitude>35000 {set rvel to ship:velocity:orbit-target :velocity:orbit.}.
- set amag to eng2:maxthrust/(ship:mass*9.81).
- //Solve for t, where 0=at^4+bt^2+ct+d. First get coefficients
- set a to 0-((amag)^2)/4.
- set b to (rvel:sqrmagnitude).
- set c to 2*(rvel*rpos).
- set d to (rpos:sqrmagnitude).
- //Do a few Newton-Raphson iterations:
- set timeguesses to list().
- timeguesses:add(initialguess).
- set position to 0.
- until position>=iterations
- {
- timeguesses:add(position-(a*timeguesses[position]^4+b*timeguesses[position]^2+c*timeguesses[position]+d)/(4*a*timeguesses[position]^3+2*b*timeguesses[position]+c)).
- set position to position+1.
- }.
- set initialguess to abs(timeguesses[iterations]).
- //Then calculate your desired direction
- set t to abs(timeguesses[iterations])/1.15.
- if altitude>35000 {set t to abs(timeguesses[iterations]).}.
- print t at (22,10).
- print target:distance at (20,12).
- set steeringvector to (v((0-2)*(rpos:x+(rvel:x)*t)/(t^2),(0-2)*(rpos:y+(rvel:y)*t)/(t^2),(0-2)*(rpos:z+(rvel:z)*t)/(t^2))+6*(up:vector)).
- set steeringangle to steeringvector.//:direction.
- print vectorangle(steeringvector,ship:facing:vector) at (16,14).
- set Vectordraw TO VECDRAWARGS(v(0,0,0), steeringvector:normalized, rgb(1,0.5,0.5),"", 12.0, true ).
- }.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement