Hi guys!
So Im trying to make a ball maze game and having problems with my code.
Right now i have built controls that will move my base plane, the plane that the ball rolls on with this code and it seems to work out.
function Update () {
if (Input.GetKey ("a")){
print ("a key was pressed");
transform.Rotate(Time.deltaTime*20, 0, 0);}
if (Input.GetKey ("a") && Input.GetKey ("s")){
transform.Rotate(Time.deltaTime*10, 0, Time.deltaTime*10);}
else if (Input.GetKey ("a") && Input.GetKey ("w")){
transform.Rotate(Time.deltaTime*10, 0, -Time.deltaTime*10);}
else if (Input.GetKey ("d")){
print ("d key was pressed");
transform.Rotate(-Time.deltaTime*20, 0, 0);}
if (Input.GetKey ("d") && Input.GetKey ("s")){
transform.Rotate(-Time.deltaTime*10, 0, Time.deltaTime*10);}
else if (Input.GetKey ("d") && Input.GetKey ("w")){
transform.Rotate(-Time.deltaTime*10, 0, -Time.deltaTime*10);}
else if (Input.GetKey ("w")){
print ("w key was pressed");
transform.Rotate(0, 0, -Time.deltaTime*20);}
if (Input.GetKey ("w") && Input.GetKey ("d")){
transform.Rotate(-Time.deltaTime*10, 0, -Time.deltaTime*10);}
else if (Input.GetKey ("w") && Input.GetKey ("a")){
transform.Rotate(Time.deltaTime*10, 0, -Time.deltaTime*10);}
else if (Input.GetKey ("s")){
print ("s key was pressed");
transform.Rotate(0, 0, Time.deltaTime*20);}
if (Input.GetKey ("s") && Input.GetKey ("d")){
transform.Rotate(-Time.deltaTime*10, 0, Time.deltaTime*10);}
else if (Input.GetKey ("s") && Input.GetKey ("a")){
transform.Rotate(Time.deltaTime*10, 0, Time.deltaTime*10);}
Problem is that I don’t know how to move the plane back to it´s original position (0,0,0).
I want this to happen when I don’t push any of my keys.
I had this at the end of my code:
else {
transform.rotation = Quaternion.identity;}
But that didn´t work out so well for me, It seems like the else statement runs all the time as well and the transform happens too fast, can i implement time.delta.time maybe?
//Cheers Mathias