A fun test that has an enemy car with twin machine guns chasing your car; with a whole lot of fun stuff thrown in.
* Twin machine gun script with alternate guns firing and various values to tweak frame rate firing, cool down period, etc
* Direction indicator arrow
* Direction/ target locator line (for debug)
* Enemy self flipping car if it topples over
* Huge rigidbody terrain mesh for all sorts of winter chase fun
* Fix your car if it flips with the ENTER key (may need to press a few times)
* Debug printing of multiple values with a single textPrint object
* Source project included
Target V6.49
Machine gun script
* Twin machine gun script with alternate guns firing and various values to tweak frame rate firing, cool down period, etc
* Direction indicator arrow
* Direction/ target locator line (for debug)
* Enemy self flipping car if it topples over
* Huge rigidbody terrain mesh for all sorts of winter chase fun
* Fix your car if it flips with the ENTER key (may need to press a few times)
* Debug printing of multiple values with a single textPrint object
* Source project included
Target V6.49
Machine gun script
Code: [Select]
int GUN1 = OBJ_0; //1st gun
int GUN2 = OBJ_22; //2nd gun
int activeGun = 1; //the active gun
int gunheat = 0; //gun heat counter
int maxheat = 100; //max heat for guns
int coolbase = 60*3; //number of frames to cool down = X seconds
bool canfire = true; //true that the gun is cool enough to fire
int fireRate = 4; //frame rate of fire.. eg every 5 frames
int frame = 0; //our frame counter
int coolerCounter; //our cooler counter
void Main()
{
//keep scanner oriented to car.. manual setting is not always accurate
Vector3 location;
Quaternion orientation;
iObjectLocation(OBJ_88,location); //get car location
iObjectOrientation(OBJ_88,orientation); //get car orientation
iObjectLocationSet(OBJ_66,location); //set scanner location
iObjectOrientationSet(OBJ_66,orientation); //set scanner orientation
iObjectStart(OBJ_66); //do a scan
if(IN_66 != -1){ //if the target is in sight, fire guns
frame ++; //tick off a frame
if(frame > fireRate){ //if the fire frame is reached fire at will
frame = 0; //reset the frame tick
activeGun++; //toggle the active gun
if(activeGun > 2){ //only 2 guns
activeGun = 1; //so switch back
}
if(canfire){ //if we can fire
switch(activeGun){ //fire alternate guns
case 1: iObjectStart(GUN1); //fire this gun
gunheat++; //add overall heat
//iObjectStop(GUN2)
break; //enough of this gun
case 2: iObjectStart(GUN2); //fire this gun
//iObjectStop(GUN1)
gunheat++; //add overall heat
break; //enough of this gun
}
if(gunheat >maxheat){ //if the guns are to hot
canfire = false; //we cant fire them
coolerCounter = coolbase; //start gun cool down
}
}
gunheat--; //cool down gun if not firing .. same rate as firing
if(gunheat <1){
gunheat = 0;
}
}
}
if(!canfire){ //if the guns are hot, and we cant fire
coolerCounter --; //count down the cooler
if(coolerCounter <1){ //if the guns are cool enough
canfire = true; //cool guns can now fire at will
gunheat = 0;
}
}
string S;
S = frame+","+activeGun+","+gunheat;
if(canfire) S+=",Y,"; else S+=",N,";
S+=coolerCounter;
iObjectTextSet(OBJ_44,S);
}