{"id":2216,"date":"2020-04-22T16:19:46","date_gmt":"2020-04-22T08:19:46","guid":{"rendered":"https:\/\/www.clonefactor.com\/wordpress\/?p=2216"},"modified":"2020-04-22T16:34:31","modified_gmt":"2020-04-22T08:34:31","slug":"%e6%88%91%e7%9a%84%e4%ba%ba%e5%bd%a2%e9%96%8b%e7%99%bc%e7%ad%86%e8%a8%98%e5%9b%9b-locomotion-%e8%a2%ab%e9%9a%9c%e7%a4%99%e7%89%a9%e5%bd%b1%e9%9f%bf%e7%9a%84%e7%a7%bb%e5%8b%95","status":"publish","type":"post","link":"https:\/\/www.clonefactor.com\/wordpress\/program\/unity3d\/2216\/","title":{"rendered":"\u6211\u7684\u4eba\u5f62\u958b\u767c\u7b46\u8a18(\u56db) Locomotion, \u88ab\u969c\u7919\u7269\u5f71\u97ff\u7684\u79fb\u52d5."},"content":{"rendered":"\n<p>\u9019\u63a5\u4e0a\u4ee5\u524d\u7684 Locomotion&nbsp;<a href=\"https:\/\/www.clonefactor.com\/wordpress\/program\/unity3d\/devlog\/2042\/\">\u6211\u7684\u4eba\u5f62\u63a7\u5236\u958b\u767c\u7b46\u8a18(\u4e00) Locomotion<\/a>,&nbsp;<\/p>\n\n\n\n<p>\u90a3\u7bc7\u53ea\u662f\u55ae\u7d14\u7684\u7528\u79fb\u52d5\u5411\u91cf\u627e\u51fa X, Z \u8ef8\u7684\u4f4d\u7f6e\u8cc7\u8a0a\u518d\u8f38\u5165\u5230 Animator \u4e2d\u6210\u70ba\u79fb\u52d5\u7684\u8cc7\u6599\u6d41.<br>\u53ea\u662f\u55ae\u55ae\u89e3\u6c7a\u4e86\u300c\u8a08\u7b97\u51fa\u5e73\u5730\u4e0a\u7684\u79fb\u52d5\u5411\u91cf\u300d<br>\u53ef\u662f\u9019\u88e1\u9762\u6709\u597d\u5e7e\u500b\u5927\u554f\u984c, \u4f8b\u5982<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>\u8a08\u7b97\u51fa\u6709\u969c\u7919\u7269\u64cb\u8457\u6642\u672a\u80fd\u9054\u6210\u9810\u5b9a\u7684\u884c\u7a0b Vector (\u5982\u78b0\u58c1\/\u7dca\u8cbc\u7246\u58c1\u884c\u8d70)<\/li><li>\u8a08\u7b97\u51fa\u55ae\u55ae\u53ea\u662f\u6b65\u8173\u79fb\u52d5\u7684Vector (\u5728\u6703\u79fb\u52d5\u7684\u5e73\u53f0\u4e0a,\u9694\u96e2\u51fa\u5e73\u53f0\u79fb\u52d5\u7684\u8cc7\u8a0a)<\/li><\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">\u672c\u7bc7\u5148\u8ad6\u4e00\u4e0b\u5728 (A) \u6709\u969c\u7919\u7269\u64cb\u8457\u7684\u60c5\u6cc1<\/h3>\n\n\n\n<p>\u5982\u679c\u53ea\u4f9d\u4e0a\u7bc7\u7684\u65b9\u5f0f\u5be6\u4f5c, \u5728\u8dd1\u5230\u7246\u58c1\u7684\u6642\u5019\u6703\u51fa\u73fe\u4e0b\u5716\u9019\u7a2e\u300c\u5411\u7246\u58c1\u8dd1\u300d\u7684\u4e0d\u5408\u7406\u52d5\u4f5c, \u539f\u56e0\u662f\u6211\u5011\u76f4\u63a5\u628a\u60f3\u8dd1\u7684 Local (Vector3) \u76f4\u63a5\u4e1f\u5230 Animator, \u800c\u6c92\u6709\u8003\u616e\u4eba\u7269\u662f\u5426\u88ab\u963b\u64cb\u7684\u60c5\u6cc1.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"475\" height=\"335\" src=\"https:\/\/www.clonefactor.com\/wordpress\/wp-content\/uploads\/2020\/04\/walk_toward_wall_issue.gif\" alt=\"\" class=\"wp-image-2221\"\/><\/figure>\n\n\n\n<p>\u9019\u90e8\u4efd\u56e0\u61c9\u5be6\u4f5c\u7684\u65b9\u5f0f\u4e0d\u540c\u6709\u4e0d\u540c\u65b9\u6cd5\u8655\u7406.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u65b9\u6cd5\u4e00, Rigidbody \u5be6\u4f5c<\/h4>\n\n\n\n<p>Rigidbody \u53ef\u4ee5\u7528 SweepTest \u505a\u9810\u5224, \u5f9e\u800c\u9810\u5148\u53d6\u5f97 vector distance \u4e26\u8a08\u7b97 wall normal projection.<br>\u4e26\u4e14\u81ea\u884c\u8a08\u7b97\u672c\u5e40\u7684\u79fb\u52d5\u5411\u91cf, \u63a1\u7528\u9019\u65b9\u6848\u7684\u8a71 Animator \u8f38\u5165\u65b9\u9762\u5012\u662f\u6bd4\u8f03\u7c21\u55ae.<br>\u53ef\u662f\u9019\u500b\u65b9\u6848\u5c0d\u8907\u96dc\u5730\u5f62\u7684\u9805\u76ee\u975e\u5e38\u4e0d\u53cb\u5584, e.g. \u4e0a\u4e0b\u5761\u5ea6, \u51f9\u51f8\u5730\u8868, \u6a13\u68af(\u53ef\u8e0f)&#8230;etc<br>\u89e3\u6c7a\u9019\u4e9b\u554f\u984c\u53ef\u80fd\u8017\u7528\u5927\u91cf\u7684\u7269\u7406\u904b\u7b97, \u9664\u975e\u95dc\u5361\u8a2d\u8a08\u4e0a\u53ef\u4ee5\u907f\u514d\u5426\u5247\u4e0d\u5efa\u8b70.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u65b9\u6cd5\u4e8c, CharacterController \u5be6\u4f5c<\/h4>\n\n\n\n<p>\u7531\u65bc CharacterController \u6703\u81ea\u5df1\u9032\u884c\u78b0\u649e\u6e2c\u8a66, \u6240\u4ee5\u4f7f\u7528\u9019\u7a2e\u65b9\u5f0f\u5012\u662f\u53ef\u4ee5\u8f15\u9b06\u89e3\u6c7a\u5f88\u591a AABB test \u7684\u7169\u60f1.<br>\u4f46\u5be6\u4f5c\u6642\u4e5f\u6709\u4e0d\u5c11\u9700\u8981\u6e96\u78ba\u5230 \u6bcf\u5e40\u7684\u4f8b\u5916\u64cd\u4f5c, \u7de8\u5beb\u6642\u5c0d\u65bc CharacterController \u7684\u5b58\u53d6\u67b6\u69cb\u9700\u8981\u4e0b\u4e00\u756a\u5fc3\u601d\u53bb\u907f\u514d\u591a\u65b9\u5b58\u53d6\u554f\u984c.<\/p>\n\n\n\n<p>\u4ee5\u65b9\u6cd5\u4e8c, \u4f86\u5be6\u4f5c (A) + (B) \u7684\u8a71\u6709\u4e00\u500b\u554f\u984c, \u4eba\u7269\u79fb\u52d5\u7684\u8ddd\u96e2\u662f\u4e0d\u53ef\u9810\u77e5\u7684\u56e0\u70ba\u672c\u5e40\u7684 CharacterController.MoveTo() \u9084\u6c92\u6709\u88ab\u547c\u53eb.<br>\u6211\u60f3\u5230\u7684\u8fa6\u6cd5\u5c31\u662f\u62d6\u5ef6\u4e00\u5e40\u4f86\u904b\u7b97. \u4e0d\u904e\u9019\u5df2\u7d93\u662f\u4e0b\u4e00\u7bc7\u7684\u5167\u5bb9, \u5728\u9019\u66ab\u4e14\u8df3\u904e&#8230;.<br>\u73fe\u5728\u5148\u4f86\u770b\u770b\u600e\u6a23\u7528\u6578\u5b78\u4f86\u89e3\u6c7a\u7528\u982d\u649e\u7246\u7684\u554f\u984c~<\/p>\n\n\n\n<p>\u8981\u8a08\u7b97\u5be6\u969b\u79fb\u52d5\u7684\u5411\u91cf\u6211\u5011\u9700\u8981\u4e0b\u9762\u7684\u8cc7\u8a0a.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u4e0a\u4e00\u5e40\u4eba\u7269\u7684\u4f4d\u7f6e(position)<\/li><li>\u672c\u5e40\u4eba\u7269\u7684\u4f4d\u7f6e(position)<\/li><li>\u672c\u5e40\u7684 Time.deltaTime &#8211; \u7528\u4ee5 distance, speed, time \u904b\u7b97&nbsp;<a href=\"https:\/\/www.clonefactor.com\/wordpress\/program\/math\/2186\/\">\u6383\u76f2\u7cfb\u5217 : Vector \u77e2\u91cf<\/a><\/li><\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">Vector3 lastPosition;\n\nprivate void FindOutLocalMovement()\n{\n    \/\/ the actually movement from last frame to current.\n    Vector3 motionVector = transform.position - lastPosition;\n    \n    \/\/ the movement in terms of local space.\n    Vector3 localMotionVector = transform.InverseTransfromDirection(motionVector);\n    \n    \/\/ since vector was presenting the distance, so (distance \/ time) = speed\n    Vector3 localXYZSpeed = motionVector \/ Time.deltaTime;\n    \n    \/\/ pass to animator\n    animator.SetFloat(\"LocalX\", localXYZSpeed.x);\n    animator.SetFloat(\"LocalY\", localXYZSpeed.y);\n    animator.SetFloat(\"LocalZ\", localXYZSpeed.z);\n    \n    \/\/ finish, update last position for next calculation.\n    lastPosition = transform.position;\n}<\/pre>\n<p>&nbsp;<\/p>\n\n\n\n<p>\u5982\u679c\u6211\u5011\u4e0d\u662f\u76f4\u63a5\u628a\u8f38\u5165\u4e1f\u9032\u53bb Animator, \u800c\u662f\u628a\u5b83\u5206\u96e2\u8a08\u7b97\u7684\u8a71, , \u52d5\u4f5c\u5c31\u81ea\u7136\u5f88\u591a\u4e86.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"475\" height=\"335\" src=\"https:\/\/www.clonefactor.com\/wordpress\/wp-content\/uploads\/2020\/04\/walk_toward_wall_fix.gif\" alt=\"\" class=\"wp-image-2222\"\/><\/figure>\n\n\n\n<p>\u5c31\u9019\u6a23, \u884c\u8d70\u7684\u6b65\u8ddd\u5c31\u6703\u56e0\u61c9\u5be6\u969b\u7684\u79fb\u52d5\u800c\u5957\u7528\u9069\u7576\u7684\u6b65\u8ddd\u5230 Animator \u4e0a.<br>\u4e0b\u4e00\u7bc7~ : \u89e3\u6c7a\u5e73\u5373\u4e0a\u7684\u79fb\u52d5<\/p>\n\n\n","protected":false},"excerpt":{"rendered":"<p>\u9019\u63a5\u4e0a\u4ee5\u524d\u7684 Locomotion&nbsp;\u6211\u7684\u4eba\u5f62\u63a7\u5236\u958b\u767c\u7b46\u8a18(\u4e00) Locomotion,&#038;n &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[78,11],"tags":[43],"class_list":["post-2216","post","type-post","status-publish","format-standard","hentry","category-math","category-unity3d","tag-unity3d-2"],"_links":{"self":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/posts\/2216","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/comments?post=2216"}],"version-history":[{"count":5,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/posts\/2216\/revisions"}],"predecessor-version":[{"id":2226,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/posts\/2216\/revisions\/2226"}],"wp:attachment":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/media?parent=2216"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/categories?post=2216"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/tags?post=2216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}