I am working on a birds eye view game in which the player uses wasd to move about. However I am running into an issue with this. For example when the player presses w the character moves forward, and when the player presses a or d the character rotates left or right. I would like to have it so so when the player presses aw at the same time It would rotate/move simultaneously.
Current Key Detection:
function OnGUI () {
//Set up hotkey "w" for Forward
if (Event.current.Equals (Event.KeyboardEvent ("w")))
ThurstersForward();
//Set up hotkey "w" for Forward
if (Event.current.Equals (Event.KeyboardEvent ("s")))
ThurstersBackward();
//Set up hotkey "d" for rotate right
if (Event.current.Equals (Event.KeyboardEvent ("d")))
rotateRight();
//Set up hotkey "a" for rotate right
if (Event.current.Equals (Event.KeyboardEvent ("a")))
rotateLeft();
}
Current Resulting Action:
function ThurstersForward(){
rigidbody.AddForce(transform.forward);
transform.Find("ThrusterA").GetComponent("EllipsoidParticleEmitter").enabled = true;
transform.Find("ThrusterB").GetComponent("EllipsoidParticleEmitter").enabled = true;
}
function ThurstersOff(){
transform.Find("ThrusterA").GetComponent("EllipsoidParticleEmitter").enabled = false;
transform.Find("ThrusterB").GetComponent("EllipsoidParticleEmitter").enabled = false;
}
function ThurstersBackward(){
rigidbody.AddForce(transform.forward * -2);
}
function rotateRight(){
Debug.Log(transform.rotation);
transform.Rotate(Vector3.up * 2);
}
function rotateLeft(){
transform.Rotate(Vector3.up * -2);
}
Any Suggestions, Right now only one can be "active" at a time. I looked into using threads but it appeared that unity did not support them.