public Vector3 GetDirection(AxisEventParam p) { var retValue = new Vector3(0, 0, 0); if (p.axis == KeyAxis.translateFw) { if (p.amount > 0) { retValue += new Vector3(0, 0, myThrust / GetComponent <Rigidbody>().mass *Time.fixedDeltaTime); } if (p.amount < 0) { retValue += new Vector3(0, 0, myThrust / GetComponent <Rigidbody>().mass *Time.fixedDeltaTime *(-1)); } } if (p.axis == KeyAxis.translateUp) { if (p.amount > 0) { retValue += new Vector3(0, myThrust / GetComponent <Rigidbody>().mass *Time.fixedDeltaTime, 0); } if (p.amount < 0) { retValue += new Vector3(0, myThrust / GetComponent <Rigidbody>().mass *Time.fixedDeltaTime *(-1), 0); } } if (p.axis == KeyAxis.translateSide) { if (p.amount > 0) { retValue += new Vector3(myThrust / GetComponent <Rigidbody>().mass *Time.fixedDeltaTime *(-1), 0, 0); } if (p.amount < 0) { retValue += new Vector3(myThrust / GetComponent <Rigidbody>().mass *Time.fixedDeltaTime, 0, 0); } } if (p.axis == KeyAxis.lightSpeed) { //TODO: enable / disable warp panel //retValue += new Vector3(0, 0, 300000000); } if (p.axis == KeyAxis.stop) { myVelX = 0; myVelY = 0; myVelZ = 0; } return(retValue); }
public void HandleAxis(AxisEventParam p) { if (p.axis == KeyAxis.vertical) { if (p.amount > 0) // ylös { this.transform.Rotate(new Vector3(-1, 0, 0)); } if (p.amount < 0) { this.transform.Rotate(new Vector3(1, 0, 0)); } } }
public void HandleAxis(AxisEventParam p) { Vector3 deltaVel = GetDirection(p); Quaternion rotations = GetComponent <Rigidbody>().rotation; Matrix4x4 m = Matrix4x4.TRS(Vector3.zero, rotations, Vector3.one); Vector3 deltaVelRotated = m.MultiplyPoint3x4(deltaVel); myVelX += deltaVelRotated.x; myVelY += deltaVelRotated.y; myVelZ += deltaVelRotated.z; var dir = GetRotation(p); GetComponent <Rigidbody>().AddRelativeTorque(dir); }
public Vector3 GetRotation(AxisEventParam p) { var retValue = new Vector3(0, 0, 0); if (p.axis == KeyAxis.vertical) { if (p.amount > 0) { retValue += new Vector3(100000, 0, 0); } if (p.amount < 0) { retValue += new Vector3(-100000, 0, 0); } } if (p.axis == KeyAxis.horizontal) { if (p.amount > 0) { retValue += new Vector3(0, 100000, 0); } if (p.amount < 0) { retValue += new Vector3(0, -100000, 0); } } if (p.axis == KeyAxis.roll) { if (p.amount > 0) { retValue += new Vector3(0, 0, -100000); } if (p.amount < 0) { retValue += new Vector3(0, 0, 100000); } } if (p.axis == KeyAxis.stopRot) { if (localAngularVelocity.magnitude < 0.001) { GetComponent <Rigidbody>().angularVelocity = Vector3.zero; } else { if (localAngularVelocity.x < 0) { retValue += new Vector3(100000, 0, 0); } if (localAngularVelocity.x > 0) { retValue += new Vector3(-100000, 0, 0); } if (localAngularVelocity.y < 0) { retValue += new Vector3(0, 100000, 0); } if (localAngularVelocity.y > 0) { retValue += new Vector3(0, -100000, 0); } if (localAngularVelocity.z < 0) { retValue += new Vector3(0, 0, 100000); } if (localAngularVelocity.z > 0) { retValue += new Vector3(0, 0, -100000); } } } /* * if (Input.GetKey (KeyCode.Keypad5)) { * * if (localAngularVelocity.x < 0) { * retValue += new Vector3 (100000, 0, 0); * } * if (localAngularVelocity.x > 0) { * retValue += new Vector3 (-100000, 0, 0); * } * if (localAngularVelocity.y < 0) { * retValue += new Vector3 (0, 100000, 0); * } * if (localAngularVelocity.y > 0) { * retValue += new Vector3 (0, -100000, 0); * } * if (localAngularVelocity.z < 0) { * retValue += new Vector3 (0, 0, 100000); * } * if (localAngularVelocity.z > 0) { * retValue += new Vector3 (0, 0, -100000); * } * }*/ return(retValue); }
// Update is called once per frame void FixedUpdate() { if (Input.GetKey(KeyCode.F1)) { //game.SwitchToHelm(false); Application.LoadLevel("helm"); } if (Input.GetKey(KeyCode.F2)) { game.SwitchToHelm(true); } if (Input.GetKey(KeyCode.F3)) { //game.SwitchToScience(); Application.LoadLevel("testscene"); } // forward axis info to active element. /*var v = Input.GetAxis("Vertical"); * Debug.Log(v); * if(v !=0) * { * AxisEventParam p = new AxisEventParam(); * p.amount = v; * p.axis=KeyAxis.vertical; * * active.SendMessage("HandleAxis",p); * }*/ AxisEventParam p = new AxisEventParam(); if (Input.GetKey(KeyCode.Keypad2)) { p.axis = KeyAxis.vertical; p.amount = 1; game.activeKeyHandler.SendMessage("HandleAxis", p); } if (Input.GetKey(KeyCode.Keypad8)) { p.axis = KeyAxis.vertical; p.amount = -1; game.activeKeyHandler.SendMessage("HandleAxis", p); } if (Input.GetKey(KeyCode.Keypad6)) { p.axis = KeyAxis.horizontal; p.amount = 1; game.activeKeyHandler.SendMessage("HandleAxis", p); } if (Input.GetKey(KeyCode.Keypad4)) { p.axis = KeyAxis.horizontal; p.amount = -1; game.activeKeyHandler.SendMessage("HandleAxis", p); } if (Input.GetKey(KeyCode.Keypad9)) { p.axis = KeyAxis.roll; p.amount = 1; game.activeKeyHandler.SendMessage("HandleAxis", p); } if (Input.GetKey(KeyCode.Keypad7)) { p.axis = KeyAxis.roll; p.amount = -1; game.activeKeyHandler.SendMessage("HandleAxis", p); } if (Input.GetKey(KeyCode.Keypad5)) { p.axis = KeyAxis.stopRot; p.amount = 1; game.activeKeyHandler.SendMessage("HandleAxis", p); } if (Input.GetKey(KeyCode.W)) { p.axis = KeyAxis.translateFw; p.amount = 1; game.activeKeyHandler.SendMessage("HandleAxis", p); } if (Input.GetKey(KeyCode.S)) { p.axis = KeyAxis.translateFw; p.amount = -1; game.activeKeyHandler.SendMessage("HandleAxis", p); } if (Input.GetKey(KeyCode.A)) { p.axis = KeyAxis.translateSide; p.amount = 1; game.activeKeyHandler.SendMessage("HandleAxis", p); } if (Input.GetKey(KeyCode.D)) { p.axis = KeyAxis.translateSide; p.amount = -1; game.activeKeyHandler.SendMessage("HandleAxis", p); } if (Input.GetKey(KeyCode.R)) { p.axis = KeyAxis.translateUp; p.amount = 1; game.activeKeyHandler.SendMessage("HandleAxis", p); } if (Input.GetKey(KeyCode.F)) { p.axis = KeyAxis.translateUp; p.amount = -1; game.activeKeyHandler.SendMessage("HandleAxis", p); } if (Input.GetKey(KeyCode.LeftShift)) { p.axis = KeyAxis.lightSpeed; p.amount = 1; game.activeKeyHandler.SendMessage("HandleAxis", p); } if (Input.GetKey(KeyCode.LeftControl)) { p.axis = KeyAxis.stop; p.amount = 1; game.activeKeyHandler.SendMessage("HandleAxis", p); } }
public Vector3 GetRotation(AxisEventParam p) { var retValue = new Vector3(0, 0, 0); //if(WarpFactor > 0) return retValue; if (p.axis == KeyAxis.vertical) { if (p.amount > 0) { retValue += new Vector3(100000, 0, 0); } if (p.amount < 0) { retValue += new Vector3(-100000, 0, 0); } } if (p.axis == KeyAxis.horizontal) { if (p.amount > 0) { retValue += new Vector3(0, 100000, 0); } if (p.amount < 0) { retValue += new Vector3(0, -100000, 0); } } if (p.axis == KeyAxis.roll) { if (p.amount > 0) { retValue += new Vector3(0, 0, -100000); } if (p.amount < 0) { retValue += new Vector3(0, 0, 100000); } } if (p.axis == KeyAxis.stopRot) { // tää pitää tehdä jokaiselle akselille erikseen! if (localAngularVelocity.magnitude < 0.005) { GetComponent <Rigidbody>().angularVelocity = Vector3.zero; } /*else if (localAngularVelocity.magnitude < 0.1) * { * if (localAngularVelocity.x < 0) { * retValue += new Vector3 (10000, 0, 0); * } * if (localAngularVelocity.x > 0) { * retValue += new Vector3 (-10000, 0, 0); * } * if (localAngularVelocity.y < 0) { * retValue += new Vector3 (0, 10000, 0); * } * if (localAngularVelocity.y > 0) { * retValue += new Vector3 (0, -10000, 0); * } * if (localAngularVelocity.z < 0) { * retValue += new Vector3 (0, 0, 10000); * } * if (localAngularVelocity.z > 0) { * retValue += new Vector3 (0, 0, -10000); * } * }*/ else { if (localAngularVelocity.x < 0) { retValue += new Vector3(100000, 0, 0); } if (localAngularVelocity.x > 0) { retValue += new Vector3(-100000, 0, 0); } if (localAngularVelocity.y < 0) { retValue += new Vector3(0, 100000, 0); } if (localAngularVelocity.y > 0) { retValue += new Vector3(0, -100000, 0); } if (localAngularVelocity.z < 0) { retValue += new Vector3(0, 0, 100000); } if (localAngularVelocity.z > 0) { retValue += new Vector3(0, 0, -100000); } } } /* * if (Input.GetKey (KeyCode.Keypad5)) { * * if (localAngularVelocity.x < 0) { * retValue += new Vector3 (100000, 0, 0); * } * if (localAngularVelocity.x > 0) { * retValue += new Vector3 (-100000, 0, 0); * } * if (localAngularVelocity.y < 0) { * retValue += new Vector3 (0, 100000, 0); * } * if (localAngularVelocity.y > 0) { * retValue += new Vector3 (0, -100000, 0); * } * if (localAngularVelocity.z < 0) { * retValue += new Vector3 (0, 0, 100000); * } * if (localAngularVelocity.z > 0) { * retValue += new Vector3 (0, 0, -100000); * } * }*/ return(retValue); }