Here's the code for my homing missile:
Now, the missile homes fine, but two missiles can't home in on a target at the same time. Two missile can have a smoketrail and move(use the applyforce) at the same time, but not home. When one missile is homing, any other missile fired will not move. -Though it does have a trail.
What's happening?
------------------
The enemy is in front of us, behind us, to the left, and to the right. This time they won't get away.
Code:
# Jedi Knight Cog Script # #This cog is not supported by LEC. flags=0x240 symbols template smoke=+smoke local flex newdist local flex lastdist local flex vecx local flex vecy local flex vecz local int playteam local vector newvel local vector oldvel local thing missile local thing player local thing target local message created message pulse end # ======================================================================================== code created: lastdist=-1; SetthingPulse(GetSenderRef(), 0.05); Return; #============================================# pulse: missile = GetSenderRef(); CreateThing(smoke, missile); if((target != -1) && Haslos(missile, target) && (target != player) && (GetThingType(target) == 2 || Getthingtype(target) == 10) && (Getplayerteam(target) != playteam)) { SetThingLook(missile, VectorSub(GetThingPos(target), GetThingPos(missile))); Newdist = vectordist(getthingpos(target), getthingpos(missile)); if((newdist > (lastdist+.1)) && (lastdist != -1)) { if(vectorx(missile) > 0.3) vecx = -0.1; else vecx = 0; if(vectory(missile) > 0.3) vecy = -0.1; else vecy = 0; if(vectorz(missile) > 0.3) vecz = -0.1; else vecz = 0; newvec = vectorset(vecx, vecy, vecz); oldvec = vectorset(vectorx(missile), vectory(missile), vectorz(missile)); Setthingvel(missile, (vectoradd(newvec, oldvec))); } else ApplyForce(missile, VectorScale(GetThingLVec(missile), 0.2)); } else { ApplyForce(missile, VectorScale(GetThingLVec(missile), 0.1)); player = Getlocalplayerthing(); playteam = GetPlayerTeam(player); target = FirstThingInView(missile, 200, 10, 0x404); } lastdist=newdist; Return; #============================================# end
Now, the missile homes fine, but two missiles can't home in on a target at the same time. Two missile can have a smoketrail and move(use the applyforce) at the same time, but not home. When one missile is homing, any other missile fired will not move. -Though it does have a trail.
What's happening?
------------------
The enemy is in front of us, behind us, to the left, and to the right. This time they won't get away.