/// <summary> /// Similar things to how the vehicle script works, but with a couple of adjustments like public control schemes /// </summary> private void Update() { Wrap(); //The difference between the vehicel script is that now you can specify the controlls and the script doesn'e have to worry about //as many parameters if (Input.GetKey(leftMove))//rotation conditions { i += 1f; j += 0.1f; dir = Quaternion.Euler(0, 0, 5f) * dir; totalRot += j; store_ = dir; } else if (Input.GetKey(rightMove)) { i -= 1f; j -= 0.1f; dir = Quaternion.Euler(0, 0, -5f) * dir; totalRot += j; store_ = dir; } if (Input.GetKey(UpMove))//Acceleration condition { acceleration = accelRate * dir; velocity += acceleration; } else//if we release the key for acceleration we deaccelerate { velocity *= deacceleration; } velocity = Vector3.ClampMagnitude(velocity, maxSpeed); transform.GetChild(0).transform.position = transform.position + dir * 1.5f; transform.GetChild(0).transform.rotation = Quaternion.Euler(0, 0, Mathf.Atan2(transform.GetChild(0).transform.position.y - transform.position.y, transform.GetChild(0).transform.position.x - transform.position.x) * Mathf.Rad2Deg); child_Rotation = transform.GetChild(0).transform.rotation; transform.position += velocity; if (det.output) { Spawn_Management var = FindObjectOfType <Spawn_Management>(); var.alive = false; det.output = false; } }
/// <summary> /// Wrap the player on screen /// Get the input and move an drotate the player according to vector math /// update the alive varibale for the spwn_Manager /// </summary> private void Update() { Wrap(); if (Input.GetKey(KeyCode.LeftArrow))//rotation conditions { i += 1f; j += 0.1f; dir = Quaternion.Euler(0, 0, 5f) * dir; totalRot += j; store_ = dir; } else if (Input.GetKey(KeyCode.RightArrow)) { i -= 1f; j -= 0.1f; dir = Quaternion.Euler(0, 0, -5f) * dir; totalRot += j; store_ = dir; } if (Input.GetKey(KeyCode.UpArrow))//Acceleration condition { acceleration = accelRate * dir; velocity += acceleration; } else//if we release the key for acceleration we deaccelerate { velocity *= deacceleration; } velocity = Vector3.ClampMagnitude(velocity, maxSpeed);//to reach a maximum speed I clamp the value transform.GetChild(0).transform.position = transform.position + dir * 1.5f; transform.GetChild(0).transform.rotation = Quaternion.Euler(0, 0, Mathf.Atan2(transform.GetChild(0).transform.position.y - transform.position.y, transform.GetChild(0).transform.position.x - transform.position.x) * Mathf.Rad2Deg); child_Rotation = transform.GetChild(0).transform.rotation; transform.position += velocity; if (det.output)//pass along the output of the collision { Spawn_Management var = FindObjectOfType <Spawn_Management>(); var.alive = false; det.output = false; } }