Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. var horizSensitivity =10;
  2. var vertSensitivity =10;
  3. var leftBound = -14;
  4. var rightBound = 14;
  5. var upperBound = 9;
  6. var lowerBound = -9;
  7.  
  8.  
  9. function FixedUpdate () {
  10.  
  11. //left screen edge
  12. if (transform.position.x <= leftBound) {
  13. //allow moving up and down while still on the side of the screen
  14. if (transform.position.y >= upperBound){
  15. if ( Input.GetAxis("Vertical") >= 0 )
  16. transform.Translate(0, Input.GetAxis("Vertical")/vertSensitivity*-1, 0);}
  17. if (transform.position.y <= lowerBound){
  18. if ( Input.GetAxis("Vertical") <= 0 )
  19. transform.Translate(0, Input.GetAxis("Vertical")/vertSensitivity*-1, 0);}
  20. if ( (transform.position.y > lowerBound) && (transform.position.y < upperBound)){
  21. transform.Translate(0, Input.GetAxis("Vertical")/vertSensitivity*-1, 0);}
  22. //get off of the edge
  23. if ( Input.GetAxis("Horizontal") >= 0 )
  24. transform.Translate(Input.GetAxis("Horizontal")/horizSensitivity, 0, 0);
  25. }
  26. //right screen edge
  27. else if (transform.position.x >= rightBound) {
  28. //allow moving up and down while still on the side of the screen
  29. if (transform.position.y >= upperBound){
  30. if ( Input.GetAxis("Vertical") >= 0 )
  31. transform.Translate(0, Input.GetAxis("Vertical")/vertSensitivity*-1, 0);}
  32. if (transform.position.y <= lowerBound){
  33. if ( Input.GetAxis("Vertical") <= 0 )
  34. transform.Translate(0, Input.GetAxis("Vertical")/vertSensitivity*-1, 0);}
  35. if ( (transform.position.y > lowerBound) && (transform.position.y < upperBound)){
  36. transform.Translate(0, Input.GetAxis("Vertical")/vertSensitivity*-1, 0);}
  37. //get off of the edge
  38. if ( Input.GetAxis("Horizontal") <= 0 )
  39. transform.Translate(Input.GetAxis("Horizontal")/horizSensitivity, 0, 0);
  40. }
  41. //top screen edge
  42. else if (transform.position.y >= upperBound) {
  43. //allow moving away from other axis' boundaries
  44. if (transform.position.x <= leftBound){
  45. if ( Input.GetAxis("Horizontal") >= 0 )
  46. transform.Translate(Input.GetAxis("Horizontal")/horizSensitivity, 0, 0);}
  47. if (transform.position.x >= rightBound){
  48. if ( Input.GetAxis("Horizontal") <= 0 )
  49. transform.Translate(Input.GetAxis("Horizontal")/horizSensitivity, 0, 0);}
  50. //if at neither edge, then still allow movement among other axis
  51. if ( (transform.position.y >leftBound) && (transform.position.y < rightBound)){
  52. transform.Translate(Input.GetAxis("Horizontal")/horizSensitivity, 0, 0);}
  53. //get off of the edge
  54. if ( Input.GetAxis("Vertical") >= 0 )
  55. transform.Translate(0, Input.GetAxis("Vertical")/vertSensitivity*-1, 0);
  56. }
  57. //bottom screen edge
  58. else if (transform.position.y <= lowerBound) {
  59. //allow moving away from other axis' boundaries
  60. if (transform.position.x <= leftBound){
  61. if ( Input.GetAxis("Horizontal") >= 0 )
  62. transform.Translate(Input.GetAxis("Horizontal")/horizSensitivity, 0, 0);}
  63. if (transform.position.x >= rightBound){
  64. if ( Input.GetAxis("Horizontal") <= 0 )
  65. transform.Translate(Input.GetAxis("Horizontal")/horizSensitivity, 0, 0);}
  66. //if at neither edge, then still allow movement among other axis
  67. if ( (transform.position.y >leftBound) && (transform.position.y < rightBound)){
  68. transform.Translate(Input.GetAxis("Horizontal")/horizSensitivity, 0, 0);}
  69. //get off of the edge
  70. if ( Input.GetAxis("Vertical") <= 0 )
  71. transform.Translate(0, Input.GetAxis("Vertical")/vertSensitivity*-1, 0);
  72.  
  73. }
  74.  
  75. else
  76. transform.Translate(Input.GetAxis("Horizontal")/horizSensitivity, Input.GetAxis("Vertical")/vertSensitivity*-1, 0);
  77.  
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement