{"id":3855,"date":"2015-05-20T15:21:24","date_gmt":"2015-05-20T12:21:24","guid":{"rendered":"http:\/\/unitycoder.com\/blog\/?p=3855"},"modified":"2015-05-20T15:21:24","modified_gmt":"2015-05-20T12:21:24","slug":"rotating-sphere-by-the-moved-distance","status":"publish","type":"post","link":"https:\/\/unitycoder.com\/blog\/2015\/05\/20\/rotating-sphere-by-the-moved-distance\/","title":{"rendered":"Rotating Sphere By The Moved Distance"},"content":{"rendered":"<p><a href=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2015\/05\/rolling_sphere_by_distance.gif\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3856\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2015\/05\/20\/rotating-sphere-by-the-moved-distance\/rolling_sphere_by_distance\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2015\/05\/rolling_sphere_by_distance.gif?fit=680%2C350&amp;ssl=1\" data-orig-size=\"680,350\" 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;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"rolling_sphere_by_distance\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2015\/05\/rolling_sphere_by_distance.gif?fit=680%2C350&amp;ssl=1\" class=\"alignnone size-full wp-image-3856\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2015\/05\/rolling_sphere_by_distance.gif?resize=680%2C350\" alt=\"rolling_sphere_by_distance\" width=\"680\" height=\"350\" \/><\/a><\/p>\n<p>How to rotate sphere based on the distance its moving.<\/p>\n<p>As in:<br \/>\n<a href=\"http:\/\/docs.autodesk.com\/3DSMAX\/12\/ENU\/3ds%20Max%202010%20Tutorials\/files\/WS1a9193826455f5ff-3a29af00119afd28e95-4398.htm\" target=\"_blank\">http:\/\/docs.autodesk.com\/3DSMAX\/12\/ENU\/3ds%20Max%202010%20Tutorials\/files\/WS1a9193826455f5ff-3a29af00119afd28e95-4398.htm<\/a><\/p>\n<p><strong>Source:<\/strong> <em>*Angle formula solved by &#8216;Denamond<\/em>&#8216;<\/p>\n<style>.gist table { margin-bottom: 0; }<\/style>\n<div style=\"tab-size: 8\" id=\"gist22593765\" class=\"gist\">\n<div class=\"gist-file\" translate=\"no\" data-color-mode=\"light\" data-light-theme=\"light\">\n<div class=\"gist-data\">\n<div class=\"js-gist-file-update-container js-task-list-container\">\n<div id=\"file-rotatebydistance-cs\" class=\"file my-2\">\n<div itemprop=\"text\"\n      class=\"Box-body p-0 blob-wrapper data type-c  \"\n      style=\"overflow: auto\" tabindex=\"0\" role=\"region\"\n      aria-label=\"RotateByDistance.cs content, created by unitycoder on 12:17PM on May 20, 2015.\"\n    ><\/p>\n<div class=\"js-check-hidden-unicode js-blob-code-container blob-code-content\">\n<p>  <template class=\"js-file-alert-template\"><\/p>\n<div data-view-component=\"true\" class=\"flash flash-warn flash-full d-flex flex-items-center\">\n  <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg><br \/>\n    <span><br \/>\n      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br \/>\n      <a class=\"Link--inTextBlock\" href=\"https:\/\/github.co\/hiddenchars\" target=\"_blank\">Learn more about bidirectional Unicode characters<\/a><br \/>\n    <\/span><\/p>\n<div data-view-component=\"true\" class=\"flash-action\">        <a href=\"{{ revealButtonHref }}\" data-view-component=\"true\" class=\"btn-sm btn\">    Show hidden characters<br \/>\n<\/a>\n<\/div>\n<\/div>\n<p><\/template><br \/>\n<template class=\"js-line-alert-template\"><br \/>\n  <span aria-label=\"This line has hidden Unicode characters\" data-view-component=\"true\" class=\"line-alert tooltipped tooltipped-e\"><br \/>\n    <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg><br \/>\n<\/span><\/template><\/p>\n<table data-hpc class=\"highlight tab-size js-file-line-container\" data-tab-size=\"4\" data-paste-markdown-skip data-tagsearch-path=\"RotateByDistance.cs\">\n<tr>\n<td id=\"file-rotatebydistance-cs-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC1\" class=\"blob-code blob-code-inner js-file-line\">using UnityEngine;<\/td>\n<\/tr>\n<tr>\n<td id=\"file-rotatebydistance-cs-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC2\" class=\"blob-code blob-code-inner js-file-line\">using System.Collections;<\/td>\n<\/tr>\n<tr>\n<td id=\"file-rotatebydistance-cs-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC3\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n<\/tr>\n<tr>\n<td id=\"file-rotatebydistance-cs-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC4\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n<\/tr>\n<tr>\n<td id=\"file-rotatebydistance-cs-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC5\" class=\"blob-code blob-code-inner js-file-line\">public class RotateByDistance : MonoBehaviour {<\/td>\n<\/tr>\n<tr>\n<td id=\"file-rotatebydistance-cs-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC6\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n<\/tr>\n<tr>\n<td id=\"file-rotatebydistance-cs-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC7\" class=\"blob-code blob-code-inner js-file-line\">\tpublic float moveSpeed = 2f;<\/td>\n<\/tr>\n<tr>\n<td id=\"file-rotatebydistance-cs-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC8\" class=\"blob-code blob-code-inner js-file-line\">\tfloat radius = 0.5f;<\/td>\n<\/tr>\n<tr>\n<td id=\"file-rotatebydistance-cs-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC9\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n<\/tr>\n<tr>\n<td id=\"file-rotatebydistance-cs-L10\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"10\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC10\" class=\"blob-code blob-code-inner js-file-line\">\tvoid Start () <\/td>\n<\/tr>\n<tr>\n<td id=\"file-rotatebydistance-cs-L11\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"11\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC11\" class=\"blob-code blob-code-inner js-file-line\">\t{<\/td>\n<\/tr>\n<tr>\n<td id=\"file-rotatebydistance-cs-L12\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"12\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC12\" class=\"blob-code blob-code-inner js-file-line\">\t\t\/\/ get sphere size from collider<\/td>\n<\/tr>\n<tr>\n<td id=\"file-rotatebydistance-cs-L13\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"13\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC13\" class=\"blob-code blob-code-inner js-file-line\">\t\tradius = GetComponent&lt;SphereCollider&gt;().radius;<\/td>\n<\/tr>\n<tr>\n<td id=\"file-rotatebydistance-cs-L14\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"14\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC14\" class=\"blob-code blob-code-inner js-file-line\">\t}<\/td>\n<\/tr>\n<tr>\n<td id=\"file-rotatebydistance-cs-L15\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"15\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC15\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n<\/tr>\n<tr>\n<td id=\"file-rotatebydistance-cs-L16\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"16\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC16\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n<\/tr>\n<tr>\n<td id=\"file-rotatebydistance-cs-L17\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"17\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC17\" class=\"blob-code blob-code-inner js-file-line\">\tvoid Update () {<\/td>\n<\/tr>\n<tr>\n<td id=\"file-rotatebydistance-cs-L18\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"18\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC18\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n<\/tr>\n<tr>\n<td id=\"file-rotatebydistance-cs-L19\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"19\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC19\" class=\"blob-code blob-code-inner js-file-line\">\t\t\/\/ get input<\/td>\n<\/tr>\n<tr>\n<td id=\"file-rotatebydistance-cs-L20\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"20\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC20\" class=\"blob-code blob-code-inner js-file-line\">\t\tfloat distance = Input.GetAxis(&quot;Horizontal&quot;)*moveSpeed*Time.deltaTime;<\/td>\n<\/tr>\n<tr>\n<td id=\"file-rotatebydistance-cs-L21\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"21\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC21\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n<\/tr>\n<tr>\n<td id=\"file-rotatebydistance-cs-L22\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"22\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC22\" class=\"blob-code blob-code-inner js-file-line\">\t\t\/\/ move<\/td>\n<\/tr>\n<tr>\n<td id=\"file-rotatebydistance-cs-L23\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"23\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC23\" class=\"blob-code blob-code-inner js-file-line\">\t\ttransform.Translate(new Vector3(distance,0,0),Space.World);<\/td>\n<\/tr>\n<tr>\n<td id=\"file-rotatebydistance-cs-L24\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"24\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC24\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n<\/tr>\n<tr>\n<td id=\"file-rotatebydistance-cs-L25\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"25\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC25\" class=\"blob-code blob-code-inner js-file-line\">\t\t\/\/ rotate based on distance<\/td>\n<\/tr>\n<tr>\n<td id=\"file-rotatebydistance-cs-L26\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"26\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC26\" class=\"blob-code blob-code-inner js-file-line\">\t\tfloat angle=(distance*180)\/(radius*Mathf.PI);<\/td>\n<\/tr>\n<tr>\n<td id=\"file-rotatebydistance-cs-L27\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"27\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC27\" class=\"blob-code blob-code-inner js-file-line\">\t\ttransform.eulerAngles += new Vector3(0,0,-angle);<\/td>\n<\/tr>\n<tr>\n<td id=\"file-rotatebydistance-cs-L28\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"28\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC28\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n<\/tr>\n<tr>\n<td id=\"file-rotatebydistance-cs-L29\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"29\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC29\" class=\"blob-code blob-code-inner js-file-line\">\t}<\/td>\n<\/tr>\n<tr>\n<td id=\"file-rotatebydistance-cs-L30\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"30\"><\/td>\n<td id=\"file-rotatebydistance-cs-LC30\" class=\"blob-code blob-code-inner js-file-line\">}<\/td>\n<\/tr>\n<\/table>\n<\/div><\/div>\n<\/p><\/div>\n<\/div><\/div>\n<div class=\"gist-meta\">\n        <a href=\"https:\/\/gist.github.com\/unitycoder\/879a93583ff121ca57c7\/raw\/8f4b2651d65845271ee73516089f84969cab7065\/RotateByDistance.cs\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a><br \/>\n        <a href=\"https:\/\/gist.github.com\/unitycoder\/879a93583ff121ca57c7#file-rotatebydistance-cs\" class=\"Link--inTextBlock\"><br \/>\n          RotateByDistance.cs<br \/>\n        <\/a><br \/>\n        hosted with &#10084; by <a class=\"Link--inTextBlock\" href=\"https:\/\/github.com\">GitHub<\/a>\n      <\/div>\n<\/p><\/div>\n<\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to rotate sphere based on the distance its moving. As in: http:\/\/docs.autodesk.com\/3DSMAX\/12\/ENU\/3ds%20Max%202010%20Tutorials\/files\/WS1a9193826455f5ff-3a29af00119afd28e95-4398.htm Source: *Angle formula solved by &#8216;Denamond&#8216; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3857,"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":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[420,3],"tags":[393,159,747,417,651,116,323,748],"class_list":["post-3855","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","category-unity3d","tag-circular","tag-distance","tag-math","tag-movement","tag-rotate","tag-rotation","tag-sphere","tag-wheel"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2015\/05\/rotating_sphere_by_distance.jpg?fit=600%2C426&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p1KTaT-10b","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/3855","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=3855"}],"version-history":[{"count":1,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/3855\/revisions"}],"predecessor-version":[{"id":3858,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/3855\/revisions\/3858"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media\/3857"}],"wp:attachment":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media?parent=3855"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/categories?post=3855"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/tags?post=3855"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}