{"id":17,"date":"2013-03-18T18:42:14","date_gmt":"2013-03-18T18:42:14","guid":{"rendered":"http:\/\/lotecsoftware.com\/unity\/blog\/?page_id=17"},"modified":"2013-03-18T21:51:09","modified_gmt":"2013-03-18T21:51:09","slug":"raisablecamera","status":"publish","type":"page","link":"http:\/\/lotecsoftware.com\/unity\/blog\/?page_id=17","title":{"rendered":"RaisableCamera"},"content":{"rendered":"<p>In third person mode, I wanted to be able to raise and lower the camera with mouse wheel. This script attached to the camera makes that happen.<\/p>\n<pre class=\"lang:c# decode:true crayon-selected\">\/* *\r\n * Attach to a camera. Adds using mouse scroll wheel to raise\/lower camera.\r\n * *\/\r\nusing UnityEngine;\r\nusing System.Collections;\r\n\r\npublic class RaisableCamera : MonoBehaviour {\r\n\tpublic float maxHeight = 10f; \/\/ No higher than this.\r\n\tpublic float minHeight = 1f; \/\/ No closer than this.\r\n\tpublic float direction = 40f; \/\/ Angle to raise: &lt;0 = ahead, &gt;0 = behind.\r\n\tpublic float sensitivity = 2f;\r\n\tprivate Transform cameraTransform;\r\n\r\n\tvoid Awake () {\r\n\t\tcameraTransform = transform;\r\n\t}\r\n\r\n\tvoid Update () {\r\n\t\tfloat dy = Input.GetAxis(\"Mouse ScrollWheel\") * sensitivity;\r\n\t\tif (dy != 0) {\r\n\t\t\t\/\/ Clamp to height.\r\n\t\t\tif (dy + cameraTransform.localPosition.y &gt; maxHeight) {\r\n\t\t\t\tdy = maxHeight - cameraTransform.localPosition.y;\r\n\t\t\t}\r\n\t\t\tif (dy + cameraTransform.localPosition.y &lt; minHeight) {\r\n\t\t\t\tdy = minHeight - cameraTransform.localPosition.y;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (dy != 0) {\r\n\t\t\tfloat dz = Mathf.Tan(Mathf.Deg2Rad * direction) * dy;\r\n\t\t\tVector3 dv = new Vector3(0, dy, -dz);\r\n\t\t\tcameraTransform.Translate(dv, cameraTransform.parent);\r\n\t\t}\r\n\t}\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In third person mode, I wanted to be able to raise and lower the camera with mouse wheel. This script attached to the camera makes that happen. \/* * * Attach to a camera. Adds using mouse scroll wheel to raise\/lower camera. * *\/ using UnityEngine; using System.Collections; public class RaisableCamera : MonoBehaviour { public [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":[],"_links":{"self":[{"href":"http:\/\/lotecsoftware.com\/unity\/blog\/index.php?rest_route=\/wp\/v2\/pages\/17"}],"collection":[{"href":"http:\/\/lotecsoftware.com\/unity\/blog\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/lotecsoftware.com\/unity\/blog\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/lotecsoftware.com\/unity\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/lotecsoftware.com\/unity\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=17"}],"version-history":[{"count":5,"href":"http:\/\/lotecsoftware.com\/unity\/blog\/index.php?rest_route=\/wp\/v2\/pages\/17\/revisions"}],"predecessor-version":[{"id":20,"href":"http:\/\/lotecsoftware.com\/unity\/blog\/index.php?rest_route=\/wp\/v2\/pages\/17\/revisions\/20"}],"wp:attachment":[{"href":"http:\/\/lotecsoftware.com\/unity\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=17"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}