{"id":27,"date":"2013-03-18T22:38:42","date_gmt":"2013-03-18T22:38:42","guid":{"rendered":"http:\/\/lotecsoftware.com\/unity\/blog\/?page_id=27"},"modified":"2013-03-18T22:38:42","modified_gmt":"2013-03-18T22:38:42","slug":"singleinputcontroller","status":"publish","type":"page","link":"http:\/\/lotecsoftware.com\/unity\/blog\/?page_id=27","title":{"rendered":"SingleInputController"},"content":{"rendered":"<p>Just a simple modified version of FPSInputController.<\/p>\n<pre class=\"lang:c# decode:true\">\/* One hand input controller. Uses left\/right keys for rotating player\r\n * and up\/down keys for moving forward\/backwards.\r\n * *\/\r\nusing UnityEngine;\r\nusing System.Collections;\r\n\r\n\/\/ Require a character controller to be attached to the same game object\r\n[RequireComponent(typeof(CharacterMotor))]\r\n\r\npublic class SingleInputController : MonoBehaviour {\r\n\tpublic float rotationSpeed = 3.0f;\r\n\tprivate CharacterMotor motor;\r\n\r\n\tvoid Awake () {\r\n\t\tmotor = GetComponent&lt;CharacterMotor&gt;();\r\n\t}\r\n\r\n\tvoid Update () {\r\n\t\t\/\/ Rotate character on left\/right.\r\n\t\ttransform.Rotate(0, Input.GetAxis(\"Horizontal\") * rotationSpeed, 0);\r\n\r\n\t\t\/\/ Walk forward\/backward on up\/down.\r\n\t\tVector3 directionVector = new Vector3(0, 0, Input.GetAxis(\"Vertical\"));\r\n\r\n\t\tif (directionVector != Vector3.zero) {\r\n\t\t\tvar directionLength = directionVector.magnitude;\r\n\t\t\tdirectionVector = directionVector \/ directionLength;\r\n\t\t\tdirectionLength = Mathf.Min(1, directionLength);\r\n\t\t\tdirectionLength = directionLength * directionLength;\r\n\t\t\tdirectionVector = directionVector * directionLength;\r\n\t\t}\r\n\r\n\t\t\/\/ Apply the direction to the CharacterMotor\r\n\t\tmotor.inputMoveDirection = transform.rotation * directionVector;\r\n\t\tmotor.inputJump = Input.GetButton(\"Jump\");\r\n\t}\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Just a simple modified version of FPSInputController. \/* One hand input controller. Uses left\/right keys for rotating player * and up\/down keys for moving forward\/backwards. * *\/ using UnityEngine; using System.Collections; \/\/ Require a character controller to be attached to the same game object [RequireComponent(typeof(CharacterMotor))] public class SingleInputController : MonoBehaviour { public float rotationSpeed = [&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\/27"}],"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=27"}],"version-history":[{"count":2,"href":"http:\/\/lotecsoftware.com\/unity\/blog\/index.php?rest_route=\/wp\/v2\/pages\/27\/revisions"}],"predecessor-version":[{"id":29,"href":"http:\/\/lotecsoftware.com\/unity\/blog\/index.php?rest_route=\/wp\/v2\/pages\/27\/revisions\/29"}],"wp:attachment":[{"href":"http:\/\/lotecsoftware.com\/unity\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=27"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}