{"id":443,"date":"2012-01-14T01:41:09","date_gmt":"2012-01-13T22:41:09","guid":{"rendered":"http:\/\/unitycoder.com\/blog\/?p=443"},"modified":"2014-05-17T01:40:44","modified_gmt":"2014-05-16T22:40:44","slug":"walking-block-rotation","status":"publish","type":"post","link":"https:\/\/unitycoder.com\/blog\/2012\/01\/14\/walking-block-rotation\/","title":{"rendered":"Walking Block Rotation"},"content":{"rendered":"<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"444\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2012\/01\/14\/walking-block-rotation\/mwalkblock1\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/01\/mwalkblock1.jpg?fit=680%2C479&amp;ssl=1\" data-orig-size=\"680,479\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"mwalkblock1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/01\/mwalkblock1.jpg?fit=680%2C479&amp;ssl=1\" class=\"alignnone size-full wp-image-444\" title=\"mwalkblock1\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/01\/mwalkblock1.jpg?resize=680%2C479\" alt=\"\" width=\"680\" height=\"479\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/01\/mwalkblock1.jpg?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/01\/mwalkblock1.jpg?resize=300%2C211&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/p>\n<p>Testing rotating \/ walking block code.. (as seen in many puzzle games)<\/p>\n<p><strong>Current progress:<\/strong><br \/>\n&#8211; Screenshot: Step.1 and Step.2 (going towards right direction)<br \/>\n&#8211; Can walk one direction..<br \/>\n&#8211; Need to add smooth movement (now it rotates 90 degrees instantly)<\/p>\n<p>*This one failed.. not going to fix it<br \/>\n(if you want the demo, I can post.. but it only works in 2 directions)<\/p>\n<p>Source (javascript)<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\npublic var pivotball:Transform&#x5B;];\r\n\r\nfunction Update () \r\n{\r\n\r\n\tif (Input.GetKeyDown(&quot;a&quot;)) \/\/ left\r\n\t{\r\n\t\t\/\/ function RotateAround (point : Vector3, axis : Vector3, angle : float) : void \r\n\t\t\r\n\t\tvar axis = Vector3(0,0,1);\r\n\t\tvar n = 0;\r\n\t\t\/\/ which point is lowest, in that direction?\r\n\t\tfor (var i:int=0;i&lt;pivotball.length;i++)\r\n\t\t{\r\n\t\t\tif (pivotball&#x5B;i].position.y&lt;transform.position.y)\r\n\t\t\t{\r\n\t\t\t\tif (pivotball&#x5B;i].position.x&lt;transform.position.x)\r\n\t\t\t\t{\r\n\t\t\t\t\tn=i;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\ttransform.RotateAround (pivotball&#x5B;n].position,axis, 90);\r\n\t}\r\n\r\n\tif (Input.GetKeyDown(&quot;d&quot;)) \/\/ right\r\n\t{\r\n\t\tvar n2=0;\r\n\t\tfor (var i2:int=0;i2&lt;pivotball.length;i2++)\r\n\t\t{\r\n\t\t\tif (pivotball&#x5B;i2].position.y&lt;transform.position.y)\r\n\t\t\t{\r\n\t\t\t\tif (pivotball&#x5B;i2].position.x&gt;transform.position.x)\r\n\t\t\t\t{\r\n\t\t\t\t\tn2=i2;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\r\n\t\tvar axis2 = Vector3(0,0,1);\r\n\t\ttransform.RotateAround (pivotball&#x5B;n2].position,axis2, -90);\r\n\t}\r\n\r\n\tif (Input.GetKeyDown(&quot;w&quot;)) \/\/ up\r\n\t{\r\n\t\tvar n3=0;\r\n\t\tfor (var i3:int=0;i3&lt;pivotball.length;i3++)\r\n\t\t{\r\n\t\t\tif (pivotball&#x5B;i3].position.y&lt;transform.position.y)\r\n\t\t\t{\r\n\t\t\t\tif (pivotball&#x5B;i3].position.z&gt;transform.position.z)\r\n\t\t\t\t{\r\n\t\t\t\t\tn3=i3;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\r\n\t\tvar axis3 = Vector3(1,0,0);\r\n\t\ttransform.RotateAround (pivotball&#x5B;n3].position,axis3, 90);\r\n\t}\r\n\r\n\tif (Input.GetKeyDown(&quot;s&quot;)) \/\/ down\r\n\t{\r\n\t\tvar n4=0;\r\n\t\tfor (var i4:int=0;i4&lt;pivotball.length;i4++)\r\n\t\t{\r\n\t\t\tif (pivotball&#x5B;i4].position.y&lt;transform.position.y)\r\n\t\t\t{\r\n\t\t\t\tif (pivotball&#x5B;i4].position.z&lt;transform.position.z)\r\n\t\t\t\t{\r\n\t\t\t\t\tn4=i4;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\r\n\t\tvar axis4 = Vector3(1,0,0);\r\n\t\ttransform.RotateAround (pivotball&#x5B;n4].position,axis4, -90);\r\n\t}\r\n\r\n\r\n}\r\n<\/pre>\n<p>Screenshot:<br \/>\n<a href=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/01\/block_walk_ss.jpg\" target=\"_blank\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2929\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2012\/01\/14\/walking-block-rotation\/block_walk_ss\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/01\/block_walk_ss.jpg?fit=710%2C522&amp;ssl=1\" data-orig-size=\"710,522\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"block_walk_ss\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/01\/block_walk_ss.jpg?fit=710%2C522&amp;ssl=1\" class=\"alignnone size-medium wp-image-2929\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/01\/block_walk_ss-300x220.jpg?resize=300%2C220\" alt=\"block_walk_ss\" width=\"300\" height=\"220\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/01\/block_walk_ss.jpg?resize=300%2C220&amp;ssl=1 300w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/01\/block_walk_ss.jpg?w=710&amp;ssl=1 710w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\n&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Testing rotating \/ walking block code.. (as seen in many puzzle games) Current progress: &#8211; Screenshot: Step.1 and Step.2 (going towards right direction) &#8211; Can walk one direction.. &#8211; Need to add smooth movement (now it rotates 90 degrees instantly) *This one failed.. not going [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":444,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[4,3],"tags":[117,115,118,116,114],"class_list":["post-443","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-demos","category-unity3d","tag-block","tag-cube","tag-puzzle","tag-rotation","tag-walking"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/01\/mwalkblock1.jpg?fit=680%2C479&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p1KTaT-79","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/443","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/comments?post=443"}],"version-history":[{"count":4,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/443\/revisions"}],"predecessor-version":[{"id":2930,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/443\/revisions\/2930"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media\/444"}],"wp:attachment":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media?parent=443"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/categories?post=443"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/tags?post=443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}