// Update is called once per frame void Update() { float dT = Time.deltaTime; //Engine EngineControl ec = target.GetComponent <EngineControl> (); ec.doUpdate(dT); w = ec.currentAngularVelocity(w); //Tilting TiltingControl tc = target.GetComponent <TiltingControl> (); Vector3 tiltRotations = tc.doUpdate(dT); //RotorBlades.rotateBlades (tiltRotations); target.transform.Rotate(tiltRotations); //Z-rotation if (TiltingControl.inputSelector == 0) { if (Input.GetKey(KeyCode.A)) { target.transform.Rotate(0, -40 * dT, 0); } else if (Input.GetKey(KeyCode.D)) { target.transform.Rotate(0, 40 * dT, 0); } } else { target.transform.Rotate(0, 40 * dT * Input.GetAxisRaw("Z-Axis"), 0); } //Rotation animation spin spinner = target.GetComponent <spin> (); Vector3 rotorSpin = spinner.spinRotor(w); var rotor = target.transform.Find("Rotor_Control"); rotor.transform.Rotate(rotorSpin); //Calculating the forces generated by virtual rotorblades float forceMag = 0.0f; for (int i = 0; i < rotorblades.Count; ++i) { GameObject g = (GameObject)rotorblades [i]; Rotorblade rb = g.GetComponent <Rotorblade> (); forceMag += rb.getForce(); } //Applying the forces target.GetComponent <Rigidbody> ().AddForce(target.transform.up * forceMag); //Should be correct }
// Use this for initialization void Start() { rg = GetComponent <Rigidbody2D>(); sp = GameObject.FindGameObjectWithTag("spin").GetComponent <spin>(); }