- Home /
 
               Question by 
               Tipo · Jul 01, 2013 at 12:20 PM · 
                cameramovementmouseposition  
              
 
              Move the camera to the left when the mousecursor is left
Hi there,
I'm just starting and have a question about the camera. I want to look from the top onto my terrain/plane with a little angle ... like 2,5D. When I move my mousecursor e.g. to the left side of the screen then the camera shall scroll to the left. This is so far I have but maybe my MainCamera has the wrong angle. Or I have the wrong axis because I can move to left and right but not forward or backward.
//JavaScript
 function Update () {
   var screenBorderLeft : float = Screen.width * 0.01f;
   var screenBorderRight : float = Screen.width * 0.99f;
   var screenBorderTop : float = Screen.height * 0.01f;
   var screenBorderBottom : float = Screen.height * 0.99f;
 
   if (Input.mousePosition.y <= screenBorderLeft)
   {
     print("ScreenWidth: " + Screen.width + " --> * 0.01 " + screenBorderLeft);
     print("left" + Input.mousePosition.y);
   }
   if (Input.mousePosition.y >= screenBorderRight)
   {
     print("right" + Input.mousePosition.y);
   }
   if (Input.mousePosition.x <= screenBorderTop)
   {
     print("ScreenHeight: " + Screen.width + " --> * 0.01 " + screenBorderTop);
     print("top" + Input.mousePosition.y);
   }
   if (Input.mousePosition.x >= screenBorderBottom)
   {
     print("bottom" + Input.mousePosition.y);
   }
 }
 
 I can get nearly all directions but not the right direction.
 
               Comment
              
 
               
              Answer by Tipo · Jul 01, 2013 at 12:59 PM
Ok got it. Totally stupid from me. I mixed the coordinates and the directions so it could never match.
So this will work for me with JavaScript:
 function Update () {
     var screenBorderLeft : float = Screen.width * 0.01f;
     var screenBorderRight : float = Screen.width * 0.99f;
     var screenBorderBottom : float = Screen.height * 0.01f;
     var screenBorderTop : float = Screen.height * 0.99f;    
     
      
      if (Input.mousePosition.y <= screenBorderBottom)
      {
          //print("bottom" + Input.mousePosition.y);
          transform.position.y -= Time.deltaTime * 10;
      }
      if (Input.mousePosition.y >= screenBorderTop)
      {
          //print("top" + Input.mousePosition.y);
          transform.position.y += Time.deltaTime * 10;
      }
      if (Input.mousePosition.x <= screenBorderLeft)
      {
          //print("left" + Input.mousePosition.x);
          transform.position.x -= Time.deltaTime * 10;
      }
      if (Input.mousePosition.x >= screenBorderRight)
      {
          //print("right" + Input.mousePosition.x);
          transform.position.x += Time.deltaTime * 10;
      }    
 }
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                