private void Move() { float xMove = 0; float zMove = 0; float axisAngle = controlManager.GetAxisLeftAngle(); if (axisAngle != 999) { //uses joy stick controls if (upsideDown == true) { axisAngle = Mathf.Atan2(Mathf.Sin(Mathf.Deg2Rad * axisAngle), Mathf.Cos(Mathf.Deg2Rad * axisAngle) * -1) * Mathf.Rad2Deg; } axisAngle = axisAngle + angleY; float distance = controlManager.GetAxisLeftDistance(); xMove = Mathf.Sin(Mathf.Deg2Rad * axisAngle) * speed * distance; zMove = Mathf.Cos(Mathf.Deg2Rad * axisAngle) * speed * distance; } else { //uses keybaord controls //sets the starting change if (controlManager.GetUp() == true) { zMove = 1; } else { if (controlManager.GetDown() == true) { zMove = -1; } } if (controlManager.GetLeft() == true) { xMove = -1; } else { if (controlManager.GetRight() == true) { xMove = 1; } } if (upsideDown == true) { zMove = zMove * -1; } //checks to see if the play is moving if (xMove != 0 || zMove != 0) { //adjsuts for the angle the player is facing float newAngle = Mathf.Deg2Rad * angleY + Mathf.Atan2(xMove, zMove); xMove = Mathf.Sin(newAngle) * speed; zMove = Mathf.Cos(newAngle) * speed; } else { xMove = 0; zMove = 0; } } rigidbody.velocity = new Vector3(xMove, rigidbody.velocity.y, zMove); }