{"id":1917,"date":"2018-01-08T04:32:21","date_gmt":"2018-01-07T20:32:21","guid":{"rendered":"http:\/\/www.clonefactor.com\/wordpress\/?p=1917"},"modified":"2018-01-08T19:05:07","modified_gmt":"2018-01-08T11:05:07","slug":"unity3d-way-to-anti-gravity-%e8%a8%88%e7%ae%97%e5%8f%8d%e5%9c%b0%e5%bf%83%e5%90%b8%e5%8a%9b%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.clonefactor.com\/wordpress\/program\/c\/1917\/","title":{"rendered":"Unity3d \u6dfa\u8ac7 Rigidbody + anti-gravity \u8a08\u7b97\u53cd\u5730\u5fc3\u5438\u529b\u65b9\u6cd5."},"content":{"rendered":"<p>\u70ba\u4e86\u80fd\u6b63\u78ba\u5730 hack U3D \u7684\u7269\u7406\u74b0\u5883, \u505a\u4e86\u9ede research, \u4e26\u4e14\u5617\u8a66\u904e\u4e0d\u540c\u7684\u65b9\u6cd5\u5f8c\u7e3d\u7d50\u4e00\u4e0b.<\/p>\n<p>\u628a RigidBody \u8a2d\u00a0isKinematic \/\u00a0useGravity \u662f\u6700\u5165\u9580\u53ca\u6700\u57fa\u672c\u7684 hack.<br \/>\n\u4f46\u5f88\u591a\u6642\u5019\u5176\u5be6\u6211\u5011\u4e26\u4e0d\u5e0c\u671b\u5b8c\u5168\u4f7f\u7528 isKinematic \u7684\u65b9\u5f0f\u4f86\u79fb\u52d5\u7269\u4ef6,<br \/>\n\u800c\u662f\u66ab\u6642\u7684\u4f9d\u4e00\u5b9a\u7684\u8def\u5f91\u79fb\u52d5, \u6240\u4ee5\u9700\u8981\u7684\u529f\u80fd\u5982\u4e0b<\/p>\n<ul>\n<li>\u9055\u53cd\u5730\u5fc3\u5438\u529b (anti-gravity)<\/li>\n<li>\u79fb\u52d5\u5230\u67d0\u500b\u4f4d\u7f6e \/ \u9032\u884c\u67d0\u7a2e\u52a0\u901f\u5ea6<\/li>\n<\/ul>\n<p>\u70ba\u4e86\u53ef\u4ee5\u771f\/\u5047\u7269\u7406\u4e26\u5b58\u6211\u5011\u5fc5\u9808\u4f7f\u7528\u5404\u7a2e\u4e0d\u540c\u7684\u8fa6\u6cd5.<\/p>\n<h1>\u95dc\u65bc Anti-gravity<\/h1>\n<h2>Sample 1)<\/h2>\n<p>\u5169\u7a2e\u6df7\u5408\u7684\u627a\u6d88\u65b9\u5f0f. \u9054\u6210\u7a7a\u4e2d\u505c\u7559\u7684\u6548\u679c.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">float m_Duration = 3f;\r\n\r\n\r\nRigidbody rb = GetComponent&lt;Rigidbody&gt;();\r\n\/\/ A) clear ALL init force\r\nrb.AddForce(-rb.velocity, ForceMode.VelocityChange);\r\n\r\nfloat endTime = Time.timeSinceLevelLoad + m_Duration;\r\nwhile (Time.timeSinceLevelLoad &lt; endTime)\r\n{\r\n\trb.AddForce(-Physics.gravity, ForceMode.Acceleration); \/\/ B) continue anti gravity, but allow to apply any other force.\r\n\tyield return new WaitForFixedUpdate();\r\n}<\/pre>\n<ul>\n<li>(A) \u627a\u6d88\u4e86RB \u73fe\u5728\u7684 velocity, \u9054\u5230\u672c\u5e40\u5728\u7a7a\u4e2d\u975c\u6b62\u7684\u74b0\u5883<\/li>\n<li>(B) \u65bc\u6bcf\u5e40\u7684\u7269\u7406\u904b\u7b97\u6301\u7e3e\u52a0\u5165\u5b8c\u5168\u76f8\u53cd\u7684\u5f15\u529b\u53c3\u6578,<\/li>\n<\/ul>\n<p>\u7c21\u55ae\u8aaa\u5982\u679c\u6c92\u6709\u5176\u4ed6\u4f5c\u7528\u529b, RB \u7684\u91cd\u529b\u52a0\u901f\u5ea6\u5728\u6642\u9650\u5167\u6703\u88ab (B) \u53d6\u6d88, \u4e26\u4fdd\u6301\u65bc\u96f6\u52a0\u901f\u5ea6 \u4f86\u9054\u5230\u6d6e\u65bc\u7a7a\u4e2d\u7684\u6548\u679c<\/p>\n<h2>Sample 2)<\/h2>\n<p>\u4f7f\u7528 Joint, FixedJoint \u6216\u8005 ConfigableJoint \u7b49, \u628a RigidBody \u9023\u7d50\u5728\u4e00\u8d77.<br \/>\n\u4e00\u822c\u7684\u79fb\u52d5\u5e73\u53f0\u4e5f\u53ef\u4ee5\u4f7f\u7528\u9019\u7a2e\u65b9\u6cd5. \u4ee4\u7269\u4ef6\u8ddf\u96a8\u5e73\u53f0\u79fb\u52d5.<br \/>\n\u70ba\u4e86\u4e0d\u5f71\u97ff\u984d\u5916\u7684\u7269\u7406\u78b0\u649e, \u61c9\u8a72\u76e1\u91cf\u907f\u514d\u4f7f\u7528 Break Force = Infinity, \u56e0\u70ba\u9019\u6a23\u6703\u5c0e\u81f4\u73a9\u5bb6\u53ef\u4ee5\u8dd1\u5230\u4e00\u4e9b\u5947\u602a\u7684\u5730\u65b9. (\u7246\u88e1\u9762\u7684\u7a7a\u9593, \u5730\u5716\u7bc4\u570d\u4ee5\u5916\u5730\u65b9&#8230;etc)<\/p>\n<h1>\u95dc\u65bc\u79fb\u52d5<\/h1>\n<p>\u5176\u5be6\u5f88\u591a\u4eba\u76f4\u63a5\u4f7f\u7528 Rigidbody.velocity \u4f86\u8986\u5beb\u52a0\u901f\u5ea6\u662f\u4e0d\u5efa\u8b70\u7684\u505a\u6cd5, \u4e5f\u6703\u884d\u751f\u5f88\u591a\u4e0d\u660e\u986f\u7684\u554f\u984c.<br \/>\nU3D \u6709\u63d0\u4f9b MovePosition \u8ddf MoveRotation \u4f86\u8655\u7406\u7269\u7406\u79fb\u52d5.<\/p>\n<p>Ref :<\/p>\n<ul>\n<li><a href=\"https:\/\/docs.unity3d.com\/ScriptReference\/Rigidbody-interpolation.html\">https:\/\/docs.unity3d.com\/ScriptReference\/Rigidbody-interpolation.html<\/a><\/li>\n<li><a href=\"https:\/\/docs.unity3d.com\/ScriptReference\/Rigidbody.MovePosition.html\">https:\/\/docs.unity3d.com\/ScriptReference\/Rigidbody.MovePosition.html<\/a><\/li>\n<li><a style=\"font-size: 1.4rem;\" href=\"https:\/\/docs.unity3d.com\/ScriptReference\/Rigidbody.MoveRotation.html\">https:\/\/docs.unity3d.com\/ScriptReference\/Rigidbody.MoveRotation.html<\/a><\/li>\n<\/ul>\n<p>\u6700\u76f4\u63a5\u53ca\u6700\u5bb9\u6613\u5ffd\u7565\u7684\u662f\u00a0Rigidbody interpolation, \u9019\u6d89\u53ca\u7269\u7406\u5f15\u64ce\u7684\u8a08\u7b97\u53caUpdate\u512a\u5316,<br \/>\n\u7531\u65bc\u7406\u89e3\u53ef\u80fd\u6709\u932f\u5148\u9644\u4e0a\u53c3\u8003\u6587 :<\/p>\n<ul>\n<li><a href=\"https:\/\/answers.unity.com\/questions\/767134\/physics-what-is-interpolate-extrapolate-discrete-c.html\">https:\/\/answers.unity.com\/questions\/767134\/physics-what-is-interpolate-extrapolate-discrete-c.html<\/a><\/li>\n<li><a style=\"font-size: 1.4rem;\" href=\"http:\/\/www.kinematicsoup.com\/news\/2016\/8\/9\/rrypp5tkubynjwxhxjzd42s3o034o8\">http:\/\/www.kinematicsoup.com\/news\/2016\/8\/9\/rrypp5tkubynjwxhxjzd42s3o034o8<\/a><\/li>\n<\/ul>\n<p><iframe loading=\"lazy\" title=\"Smooth Motion in Unity\" width=\"1260\" height=\"709\" src=\"https:\/\/www.youtube.com\/embed\/qtV8JEIq0Ng?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen><\/iframe><\/p>\n<h1>\u4e3b\u8981\u9700\u6aa2\u8996\u7684\u554f\u984c\u662f<\/h1>\n<ul>\n<li>Rigidbody \u8a08\u7b97\u662f\u600e\u6a23\u53bb\u8a08\u7b97\u901f\u5ea6\u7684\u65b9\u6cd5\u53ca\u5224\u65b7\u662f\u5426\u6709\u78b0\u649e (AABB).<\/li>\n<li>\u9762\u5c0d Update, FixedUpdate, \u5f15\u64ce\u662f\u600e\u6a23\u5224\u65b7\u7269\u4ef6\u8a72\u7e6a\u756b\u5728\u751a\u9ebc\u5730\u65b9.<\/li>\n<\/ul>\n<p>\u7c21\u55ae\u7684\u57fa\u672c\u8a8d\u77e5\u662f\u5f15\u64ce\u6700\u5c11\u6bcf 0.2\u79d2\u6703\u9032\u884c\u4e00\u6b21\u7684\u7269\u7406\u904b\u7b97 (FixedUpdate). \u4f46\u9019\u500b\u904b\u7b97\u6642\u9593\u662f\u6d6e\u52d5\u7684.<br \/>\n\u800c\u4e14GPU \u5728\u60c5\u6cc1\u8a31\u53ef\u7684\u60c5\u6cc1\u4e0b\u6703\u5118\u53ef\u80fd\u591a\u5730\u9032\u884c frame \u7e6a\u756b, \u5373\u662f FPS, \u4e00\u822c\u5728 30 \u53ca 60 fps \u70ba\u6307\u6a19, \u9019\u500b\u7e6a\u756b\u6642\u9593\u4e5f\u662f\u6d6e\u52d5\u7684.<\/p>\n<p>\u90a3\u9ebc\u554f\u984c\u5c31\u662f\u5728\u4e00\u6b21 FixedUpdate \u8ddf\u4e0b\u4e00\u6b21 FixedUpdate \u671f\u9593, \u9032\u884c Update \u7e6a\u756b\u6642\u7269\u4ef6\u5b58\u5728\u751a\u9ebc\u5730\u65b9?!<br \/>\n\u800c\u6211\u5011\u5728\u8655\u7406\u904a\u6232\u6642\u5f88\u591a\u6642\u662f\u5e0c\u671b\u4f7f\u7528\u5f15\u64ce\u672c\u8eab\u7684\u7269\u7406\u904b\u7b97\u4f5c\u79fb\u52d5(\u56e0\u70ba\u770b\u8d77\u4f86\u66f4\u771f\u5be6),<br \/>\n\u4f46\u540c\u6642\u4e5f\u4e0d\u5e0c\u671b\u9019\u6a23\u505a (\u56e0\u70ba\u6211\u5011\u4e0d\u5e0c\u671b\u505a\u7528\u7269\u7406\u8a08\u7b97\u4f86 \u8dd1\u6a13\u68af, \u6216\u8005\u9032\u884c\u683c\u9b25&#8230;)<\/p>\n<p>&nbsp;<\/p>\n<h2>\u90a3\u9ebc U3D \u63d0\u4f9b\u7684 MovePosition \u8ddf MoveRotation \u8ddf\u9019\u500b\u6709\u5565\u95dc\u4fc2?<\/h2>\n<p><span style=\"font-size: 1.4rem;\">\u5c31\u662f\u7576 Interpolation \u70ba\u958b\u555f\u72c0\u614b\u6642,<\/span>\u5f15\u64ce\u6703\u4f9d\u7167\u8a2d\u5b9a\u7684\u65b9\u5f0f\u4f86\u9810\u5224\u7269\u4ef6\u7684\u7e6a\u756b\u4f4d\u7f6e. \u6700\u91cd\u8981\u7684\u662f\u6b63\u78ba\u5730\u8a08\u7b97\u7269\u4ef6\u5728\u79fb\u52d5\u6642\u662f\u5426\u6709\u63a5\u89f8 (AABB)<\/p>\n<blockquote><p>e.g. \u4e00\u500b Velocity = 1000000 \u7684\u706b\u7bad\u5f9e A \u5230 B \u53ea\u9700\u8981\u5c11\u65bc 1 \u5e40\u7684\u6642\u9593. \u5982\u679c A \u8ddf B \u9ede\u4e2d\u9593\u6709\u4e00\u500b 1 unit \u7684 cube \u662f\u5426\u80fd\u901a\u904e.<\/p><\/blockquote>\n<p>\u4ee5\u4e0a\u4f8b\u5b50\u5728 interpolation \u70ba None \u6642\u662f\u53ef\u4ee5\u76f4\u63a5\u901a\u904e\u7684. \u958b\u555f\u5247\u53ef\u4ee5\u9054\u5230\u6b63\u78ba\u7684\u78b0\u649e\u6aa2\u6e2c, \u4f46\u4e5f\u8f03\u70ba\u6786\u6548\u80fd.<\/p>\n<p>\u4f7f\u7528\u6642\u9700\u6ce8\u610f.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u70ba\u4e86\u80fd\u6b63\u78ba\u5730 hack U3D \u7684\u7269\u7406\u74b0\u5883, \u505a\u4e86\u9ede research, \u4e26\u4e14\u5617\u8a66\u904e\u4e0d\u540c\u7684\u65b9\u6cd5\u5f8c\u7e3d\u7d50 &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,11],"tags":[16,43],"class_list":["post-1917","post","type-post","status-publish","format-standard","hentry","category-c","category-unity3d","tag-c-2","tag-unity3d-2"],"_links":{"self":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/posts\/1917","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=1917"}],"version-history":[{"count":0,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/posts\/1917\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1917"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1917"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1917"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}