Advertisement
Guest User

Untitled

a guest
Jan 31st, 2014
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. private void MoveCamera()
  2. {
  3. float xPos = Input.mousePosition.x;
  4. float yPos = Input.mousePosition.y;
  5. Vector3 movement = new Vector3(0,0,0);
  6.  
  7. //horizontal movement
  8. if(xPos >= 0 && xPos < ResourceManager.scrollWidth)
  9. {
  10. movement.x=-Time.deltaTime*ResourceManager.scrollSpeed;
  11. }
  12. else if(xPos <= Screen.width && xPos > Screen.width - ResourceManager.scrollWidth)
  13. {
  14. movement.x=Time.deltaTime*ResourceManager.scrollSpeed;
  15. }
  16.  
  17. //vertical movement
  18. if(yPos >= 0 && yPos < ResourceManager.scrollWidth)
  19. {
  20. movement.z=-Time.deltaTime*ResourceManager.scrollSpeed;
  21. }
  22. else if (yPos <= Screen.height && yPos > Screen.height-ResourceManager.scrollWidth)
  23. {
  24. movement.z=Time.deltaTime*ResourceManager.scrollSpeed;
  25. }
  26.  
  27. //makes the movement take the rotation of the camera into account
  28. movement = Camera.main.transform.TransformDirection(movement);
  29. movement.y=0;
  30.  
  31. //find movement direction
  32. Vector3 origin = Camera.main.transform.position;
  33. Vector3 destination = origin;
  34. destination.x+=movement.x;
  35. destination.z+=movement.z;
  36.  
  37. //move camera if the XZ-position has changed
  38. if(destination!=origin)
  39. {
  40. Camera.main.transform.position = Vector3.MoveTowards(origin, destination, ResourceManager.maxCameraMoveSpeed);
  41. }
  42.  
  43. //set zoom
  44. movement.y-=ResourceManager.zoomSpeed*Input.GetAxis("Mouse ScrollWheel");
  45.  
  46. destination=origin;
  47. destination.y+=movement.y;
  48. destination.y=Mathf.Clamp (destination.y, ResourceManager.minCameraHeight, ResourceManager.maxCameraHeight);
  49.  
  50. //move camera if Y-position has changed
  51. if(destination!=origin)
  52. {
  53. Camera.main.transform.position = destination;
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement