Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var horizSensitivity =10;
- var vertSensitivity =10;
- var leftBound = -14;
- var rightBound = 14;
- var upperBound = 9;
- var lowerBound = -9;
- function FixedUpdate () {
- //left screen edge
- if (transform.position.x <= leftBound) {
- //allow moving up and down while still on the side of the screen
- if (transform.position.y >= upperBound){
- if ( Input.GetAxis("Vertical") >= 0 )
- transform.Translate(0, Input.GetAxis("Vertical")/vertSensitivity*-1, 0);}
- if (transform.position.y <= lowerBound){
- if ( Input.GetAxis("Vertical") <= 0 )
- transform.Translate(0, Input.GetAxis("Vertical")/vertSensitivity*-1, 0);}
- if ( (transform.position.y > lowerBound) && (transform.position.y < upperBound)){
- transform.Translate(0, Input.GetAxis("Vertical")/vertSensitivity*-1, 0);}
- //get off of the edge
- if ( Input.GetAxis("Horizontal") >= 0 )
- transform.Translate(Input.GetAxis("Horizontal")/horizSensitivity, 0, 0);
- }
- //right screen edge
- else if (transform.position.x >= rightBound) {
- //allow moving up and down while still on the side of the screen
- if (transform.position.y >= upperBound){
- if ( Input.GetAxis("Vertical") >= 0 )
- transform.Translate(0, Input.GetAxis("Vertical")/vertSensitivity*-1, 0);}
- if (transform.position.y <= lowerBound){
- if ( Input.GetAxis("Vertical") <= 0 )
- transform.Translate(0, Input.GetAxis("Vertical")/vertSensitivity*-1, 0);}
- if ( (transform.position.y > lowerBound) && (transform.position.y < upperBound)){
- transform.Translate(0, Input.GetAxis("Vertical")/vertSensitivity*-1, 0);}
- //get off of the edge
- if ( Input.GetAxis("Horizontal") <= 0 )
- transform.Translate(Input.GetAxis("Horizontal")/horizSensitivity, 0, 0);
- }
- //top screen edge
- else if (transform.position.y >= upperBound) {
- //allow moving away from other axis' boundaries
- if (transform.position.x <= leftBound){
- if ( Input.GetAxis("Horizontal") >= 0 )
- transform.Translate(Input.GetAxis("Horizontal")/horizSensitivity, 0, 0);}
- if (transform.position.x >= rightBound){
- if ( Input.GetAxis("Horizontal") <= 0 )
- transform.Translate(Input.GetAxis("Horizontal")/horizSensitivity, 0, 0);}
- //if at neither edge, then still allow movement among other axis
- if ( (transform.position.y >leftBound) && (transform.position.y < rightBound)){
- transform.Translate(Input.GetAxis("Horizontal")/horizSensitivity, 0, 0);}
- //get off of the edge
- if ( Input.GetAxis("Vertical") >= 0 )
- transform.Translate(0, Input.GetAxis("Vertical")/vertSensitivity*-1, 0);
- }
- //bottom screen edge
- else if (transform.position.y <= lowerBound) {
- //allow moving away from other axis' boundaries
- if (transform.position.x <= leftBound){
- if ( Input.GetAxis("Horizontal") >= 0 )
- transform.Translate(Input.GetAxis("Horizontal")/horizSensitivity, 0, 0);}
- if (transform.position.x >= rightBound){
- if ( Input.GetAxis("Horizontal") <= 0 )
- transform.Translate(Input.GetAxis("Horizontal")/horizSensitivity, 0, 0);}
- //if at neither edge, then still allow movement among other axis
- if ( (transform.position.y >leftBound) && (transform.position.y < rightBound)){
- transform.Translate(Input.GetAxis("Horizontal")/horizSensitivity, 0, 0);}
- //get off of the edge
- if ( Input.GetAxis("Vertical") <= 0 )
- transform.Translate(0, Input.GetAxis("Vertical")/vertSensitivity*-1, 0);
- }
- else
- transform.Translate(Input.GetAxis("Horizontal")/horizSensitivity, Input.GetAxis("Vertical")/vertSensitivity*-1, 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement