{"id":2035,"date":"2019-05-30T18:38:04","date_gmt":"2019-05-30T10:38:04","guid":{"rendered":"https:\/\/www.clonefactor.com\/wordpress\/?p=2035"},"modified":"2019-05-30T18:38:06","modified_gmt":"2019-05-30T10:38:06","slug":"%e5%9c%a8-collider-%e4%b8%8a%e9%9a%a8%e6%a9%9f%e6%89%be%e4%b8%80%e5%80%8b%e8%91%97%e5%bd%88%e9%bb%9e","status":"publish","type":"post","link":"https:\/\/www.clonefactor.com\/wordpress\/public\/2035\/","title":{"rendered":"\u5728 Collider \u4e0a\u96a8\u6a5f\u627e\u4e00\u500b\u8457\u5f48\u9ede."},"content":{"rendered":"\n<p>\u70ba\u4e86\u4e0d\u6d6a\u8cbb NPC \u5c04\u7684\u5b50\u5f48, \u53c8\u4e0d\u5e0c\u671b\u73a9\u5bb6\u8eab\u4e2d\u591a\u69cd, \u6211\u5011\u5f88\u591a\u6642\u5019\u6703\u5728\u73a9\u5bb6\u9031\u906d\u627e\u4e00\u4e9b\u969c\u7919\u7269\u4f86\u7d66 NPC \u5c04\u64ca.<\/p>\n<p>\u4e00\u65b9\u9762\u7d66\u73a9\u5bb6\u7d66\u6210\u7dca\u5f35\u611f, \u53e6\u4e00\u65b9\u9762\u8457\u5f48\u9ede\u4e5f\u53ef\u4ee5\u5408\u7406\u7684\u64ad\u653eparticle \u6548\u679c.<br \/>\u63d0\u5347\u627e\u5165\u611f.<\/p>\n<p>\u90a3\u9ebc\u5982\u4f55\u6a19\u793a\u9019\u4e9b\u8457\u5f48\u9ede\u5c31\u8981\u82b1\u9ede\u5fc3\u601d\u4e86.<\/p>\n<p>\u00a0<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">private bool GetInterestShootablePoint(Vector3 playerHeadPos, Vector3 firedPoint, out Vector3 point)\n\t{\n\t\tint hitted = aroundPlayerHead.OverlapNonAlloc(playerHeadPos, _attractFieldArea, ref markedObjs, _bulletAttractLayer, QueryTriggerInteraction.Ignore);\n\n\t\tif (_debugDeviation)\n\t\t\tDebugExtend.DrawCircle(playerHeadPos, Vector3.up, s_AimTarget, _attractFieldArea, s_DebugShootingLine, true);\n\n\t\tif (hitted == 0)\n\t\t{\n\t\t\tpoint = default;\n\t\t\t \/\/ can't find anything interest shoot point in range.\n\t\t\treturn false;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tint rnd = UnityEngine.Random.Range(0, hitted);\n\t\t\tCollider selected = markedObjs[rnd];\n\t\t\tQuaternion quat = Quaternion.LookRotation(playerHeadPos - firedPoint);\n\t\t\tVector3 boxCenter = selected.bounds.center;\n\t\t\tVector3 factor = selected.bounds.extents;\n\t\t\tfloat hFactor = Mathf.Max(factor.x, factor.z);\n\t\t\tfloat vFactor = factor.y;\n\t\t\tfloat rndHor = UnityEngine.Random.Range(-hFactor, hFactor);\n\t\t\tfloat rndVert = UnityEngine.Random.Range(-vFactor, vFactor);\n\t\t\tMatrix4x4 matrix = Matrix4x4.TRS(boxCenter, quat, Vector3.one);\n\t\t\tpoint = matrix.MultiplyPoint(MemoryManager.V3(rndHor, rndVert, 0f));\n\t\t\tif (_debugDeviation)\n\t\t\t{\n\t\t\t\tDebugExtend.DrawPoint(matrix.MultiplyPoint(MemoryManager.V3(0f, vFactor,0f)), s_ColorSizeDetection, 0.2f, s_DebugShootingLine);\n\t\t\t\tDebugExtend.DrawPoint(matrix.MultiplyPoint(MemoryManager.V3(0f,-vFactor, 0f)), s_ColorSizeDetection, 0.2f, s_DebugShootingLine);\n\t\t\t\tDebugExtend.DrawPoint(matrix.MultiplyPoint(MemoryManager.V3(hFactor, 0f, 0f)), s_ColorSizeDetection, 0.2f, s_DebugShootingLine);\n\t\t\t\tDebugExtend.DrawPoint(matrix.MultiplyPoint(MemoryManager.V3(-hFactor, 0f, 0f)), s_ColorSizeDetection, 0.2f, s_DebugShootingLine);\n\t\t\t}\n\n\t\t\tpoint = selected.ClosestPoint(point);\n\t\t\tif (_debugDeviation)\n\t\t\t{\n\t\t\t\tDebug.DrawLine(firedPoint, playerHeadPos, s_AimTarget, s_DebugShootingLine, true); \/\/ Org path.\n\t\t\t\tDebug.DrawLine(firedPoint, point, s_ColorSafeAttack, s_DebugShootingLine, true); \/\/ final selection.\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t}<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>\u529f\u80fd\u5f88\u7c21\u55ae,\u00a0<\/p>\n<p>\u63d0\u4f9b <code>playerHeadPos<\/code> \u73a9\u5bb6\u7684\u982d\u90e8\u4f4d\u7f6e, \u4ee5\u5176\u5713\u9031\u7bc4\u570d\u53d6\u5f97\u9644\u8fd1\u53ef\u7528\u7684\u969c\u7919\u7269,<br \/>\u5728 NPC \u9700\u8981 &#8220;\u5c04\u4e0d\u4e2d&#8221; \u73a9\u5bb6\u6642\u5373\u4ee5\u9031\u906d\u7684 Collider \u70ba\u76ee\u6a19\u767c\u5c04.<br \/><br \/><\/p>\n<p>\u00a0<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"777\" height=\"591\" src=\"https:\/\/www.clonefactor.com\/wordpress\/wp-content\/uploads\/2019\/05\/NPCBulletAttactSystem.png\" alt=\"\" class=\"wp-image-2037\" srcset=\"https:\/\/www.clonefactor.com\/wordpress\/wp-content\/uploads\/2019\/05\/NPCBulletAttactSystem.png 777w, https:\/\/www.clonefactor.com\/wordpress\/wp-content\/uploads\/2019\/05\/NPCBulletAttactSystem-300x228.png 300w, https:\/\/www.clonefactor.com\/wordpress\/wp-content\/uploads\/2019\/05\/NPCBulletAttactSystem-768x584.png 768w\" sizes=\"auto, (max-width: 777px) 100vw, 777px\" \/><figcaption>Enemies shoot near by player<\/figcaption><\/figure>\n\n\n\n<p>\u53d6\u5f97 Collider \u5f8c\u624d\u662f\u6709\u8da3\u7684\u5730\u65b9, \u7e3d\u4e0d\u6210\u6c38\u9060\u6253 Collider \u4e2d\u67d0\u4e00\u500b\u4f4d\u7f6e, \u6240\u4ee5\u6211\u5011\u8981\u505a\u9ede\u96a8\u6a5f, \u9019\u8981\u6c42\u5230\u8a08\u7b97 Collider \u4e2d\u53ef\u7528\u7684\u9ad4\u7a4d.<\/p>\n<p>\u53d6\u5f97 `Collider.Bound` \u70ba\u53c3\u8003, \u9019\u6771\u897f\u53ea\u662f\u986f\u793a\u5c64\u9762\u4e0a\u7684 bound box, \u4e0d\u662f\u9019\u6771\u897f (Mesh) \u7684\u5be6\u969b\u9ad4\u7a4d,<br \/>\u53d6\u5f97 bound \u5f8c center + extents \u5c31\u80fd\u5920\u77e5\u9053\u9019\u6771\u897f\u7684\u4e09\u7dad\u9ad4\u7a4d\u4e86.<\/p>\n<p>\u5c31\u53ef\u4ee5\u7528 X, Y \u4f86\u6c7a\u5b9a\u5c04\u64ca\u9019\u500b Mesh \u4e2d\u6709\u6548\u7684\u7bc4\u570d.<br \/>\u6c7a\u5b9a\u597d\u4f4d\u7f6e\u5f8c, \u56e0\u70ba\u6211\u5011\u662f\u7528\u6295\u6620\u4f86\u904b\u7b97\u9019\u96a8\u6a5f\u9ede,<\/p>\n<p>\u628a\u9019\u500b bound box \u4ee5 NPC \u9762\u5411 Player \u7684vector\u89d2\u5ea6\u70ba\u8ef8, \u6295\u5f71\u6210\u5e73\u9762.<br \/>\u628a\u9019\u500b bound box \u8f49\u63db\u70ba Matrix \u5f8c\u5c31\u53ef\u4ee5\u7528 multilypoint() \u4f86\u63db\u7b97 world position.<\/p>\n<p>\u6700\u5f8c\u5c31\u53ea\u662f\u628a\u5b50\u5f48\u4f9d\u8457\u65b0\u7684\u8457\u5f48\u9ede\u89d2\u5ea6\u767c\u5c04\u5373\u53ef.<\/p>\n\n\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.clonefactor.com\/wordpress\/?attachment_id=2038\"><img loading=\"lazy\" decoding=\"async\" width=\"766\" height=\"684\" src=\"https:\/\/www.clonefactor.com\/wordpress\/wp-content\/uploads\/2019\/05\/boundFind_UpDownLeftRight.png\" alt=\"\" class=\"wp-image-2038\" srcset=\"https:\/\/www.clonefactor.com\/wordpress\/wp-content\/uploads\/2019\/05\/boundFind_UpDownLeftRight.png 766w, https:\/\/www.clonefactor.com\/wordpress\/wp-content\/uploads\/2019\/05\/boundFind_UpDownLeftRight-300x268.png 300w\" sizes=\"auto, (max-width: 766px) 100vw, 766px\" \/><\/a><figcaption>The blue circle showing that slice plane based on NPC perspective<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u70ba\u4e86\u4e0d\u6d6a\u8cbb NPC \u5c04\u7684\u5b50\u5f48, \u53c8\u4e0d\u5e0c\u671b\u73a9\u5bb6\u8eab\u4e2d\u591a\u69cd, \u6211\u5011\u5f88\u591a\u6642\u5019\u6703\u5728\u73a9\u5bb6\u9031\u906d\u627e\u4e00\u4e9b\u969c\u7919\u7269\u4f86\u7d66 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":[3],"tags":[],"class_list":["post-2035","post","type-post","status-publish","format-standard","hentry","category-public"],"_links":{"self":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/posts\/2035","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=2035"}],"version-history":[{"count":0,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/posts\/2035\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/media?parent=2035"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/categories?post=2035"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/tags?post=2035"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}