{"id":4101,"date":"2021-08-03T21:10:47","date_gmt":"2021-08-04T02:10:47","guid":{"rendered":"https:\/\/www.incredigeek.com\/home\/?p=4101"},"modified":"2021-08-03T21:11:51","modified_gmt":"2021-08-04T02:11:51","slug":"unity-rotate-object-by-dragging-finger-on-screen","status":"publish","type":"post","link":"https:\/\/www.incredigeek.com\/home\/unity-rotate-object-by-dragging-finger-on-screen\/","title":{"rendered":"Unity &#8211; Rotate Player by Dragging Finger on Screen"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2021\/08\/image.png\"><img loading=\"lazy\" decoding=\"async\" width=\"798\" height=\"274\" src=\"https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2021\/08\/image.png\" alt=\"\" class=\"wp-image-4102\" srcset=\"https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2021\/08\/image.png 798w, https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2021\/08\/image-300x103.png 300w, https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2021\/08\/image-768x264.png 768w, https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2021\/08\/image-500x172.png 500w\" sizes=\"auto, (max-width: 798px) 100vw, 798px\" \/><\/a><figcaption>C# Code for rotating a player in Unity by swiping on the screen.<\/figcaption><\/figure>\n\n\n\n<p>This is actually really simple to do.  Create a script called PlayerRotation or something, then put in the following code.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> \n public float speed;\n void Update()\n    {\n        \/\/ Touch controls for rotation\n        if (Input.touchCount > 0 &amp;&amp; Input.GetTouch(0).phase == TouchPhase.Moved)\n        {\n            Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;\n            \/\/ Rotate Player.  Could change Rotate to Translate to move the player.\n            transform.Rotate(0, touchDeltaPosition.x * speed, 0);\n   \n\n    }<\/code><\/pre>\n\n\n\n<p>Assign the Script to the player and specify the speed in the Unity Inspector.  The public float speed variable will increase or decrease how fast you rotate around.  You can also set it to a negative number to rotate the opposite direction you drag with your finger.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2021\/08\/image-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"343\" height=\"79\" src=\"https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2021\/08\/image-1.png\" alt=\"\" class=\"wp-image-4103\" srcset=\"https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2021\/08\/image-1.png 343w, https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2021\/08\/image-1-300x69.png 300w\" sizes=\"auto, (max-width: 343px) 100vw, 343px\" \/><\/a><figcaption>Unity speed of rotation for player.<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>This is actually really simple to do. Create a script called PlayerRotation or something, then put in the following code. Assign the Script to the player and specify the speed in the Unity Inspector. The public float speed variable will &hellip; <a href=\"https:\/\/www.incredigeek.com\/home\/unity-rotate-object-by-dragging-finger-on-screen\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[325],"tags":[541,82,1244,1243,606,1242,326,327],"class_list":["post-4101","post","type-post","status-publish","format-standard","hentry","category-unity3d","tag-android","tag-c","tag-ios","tag-mobile","tag-programming","tag-rotate","tag-unity","tag-unity3d"],"_links":{"self":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/4101","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/comments?post=4101"}],"version-history":[{"count":3,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/4101\/revisions"}],"predecessor-version":[{"id":4106,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/4101\/revisions\/4106"}],"wp:attachment":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/media?parent=4101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/categories?post=4101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/tags?post=4101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}