Hello everyone, my problem is this: I am using the following code as a control for my airplane, and works very well as I wanted, but when the plane collides with some object with a helper collider, the plane lost control. Anybody know how can I fix this?
var DiamondSound : AudioClip;
static var money = 0;
static var airplaneangley: float=0.0;
static var rotationx:float =0.0;
static var rotationy:float =0.0;
static var rotationz:float =0.0;
var positionx: float=0.0;
static var positiony: float=0.0;
var positionz: float=0.0;
static var speed:float =15.0;
var uplift:float =0.0;
var rightleftsoft:float=0.0; // Variable for soft curveflight
var rightleftsoftabs:float=0.0; // Positive rightleftsoft Variable
var divesalto:float =0.0; // blocks the forward salto
var diveblocker:float=0.0; // blocks sideways stagger flight while dive
function OnTriggerEnter (other : Collider) {
if (other.gameObject.tag == "diamonds")
{
money+=1;
audio.clip = DiamondSound;
audio.Play();
Destroy(other.gameObject);
}
}
function Update () {
airplaneangley= transform.eulerAngles.y;
rotationx=transform.eulerAngles.x;
rotationy=transform.eulerAngles.y;
rotationz=transform.eulerAngles.z;
positionx=transform.position.x;
positiony=transform.position.y;
positionz=transform.position.z;
if ((Input.GetAxis("Vertical")<=0)) {
transform.Rotate((Input.GetAxis("Vertical")*Time.deltaTime*80),0,0);
}
if ((Input.GetAxis("Vertical")>0)){
transform.Rotate((Input.GetAxis("Vertical")*Time.deltaTime*80),0,0);
}
if (speed>0) transform.Rotate(0,Time.deltaTime*100*rightleftsoft,0,Space.World);
if (speed>0) transform.Rotate(0,0,Time.deltaTime*100*(1.0-rightleftsoftabs-diveblocker)*Input.GetAxis("Horizontal")*-1.0);
if ((Input.GetAxis ("Horizontal")<0)&&(rotationz >0)&&(rotationz <90)) rightleftsoft=rotationz*2.2/100*-1;// to the left
if ((Input.GetAxis ("Horizontal")>0)&&(rotationz >270)) rightleftsoft=(7.92-rotationz*2.2/100);//to the right
if (rightleftsoft>1) rightleftsoft =1;
if (rightleftsoft<-1) rightleftsoft =-1;
if ((rightleftsoft>-0.01) && (rightleftsoft<0.01)) rightleftsoft=0.0;
rightleftsoftabs=Mathf.Abs(rightleftsoft);
if (rotationx < 90) divesalto=rotationx/10.0;//Updown
if (rotationx > 90) divesalto=rotationx/-10.0;//Updown
if (rotationx <90) diveblocker=rotationx/200.0;
else diveblocker=0;
if ((rotationz <90)&&(Input.GetAxis ("Horizontal")>0)) transform.Rotate(0,0,rightleftsoft*Time.deltaTime*80);
if ((rotationz >90)&&(Input.GetAxis ("Horizontal")<0)) transform.Rotate(0,0,rightleftsoft*Time.deltaTime*80);
if (!Input.GetButton ("Horizontal")){
if ((rotationz < 135)) transform.Rotate(0,0,rightleftsoftabs*Time.deltaTime*-100);
if ((rotationz > 225)) transform.Rotate(0,0,rightleftsoftabs*Time.deltaTime*100);
}
if ((!Input.GetButton ("Vertical"))&&(groundtrigger.triggered==0)){
if ((rotationx >0)&&(rotationx < 180)) transform.Rotate(Time.deltaTime*-1,0,0);
if ((rotationx >0)&&(rotationx > 180)) transform.Rotate(Time.deltaTime*1,0,0);
}
transform.Translate(0,0,speed*Time.deltaTime);
}