{"id":465,"date":"2016-07-27T08:34:18","date_gmt":"2016-07-26T23:34:18","guid":{"rendered":"http:\/\/hajimete-program.com\/blog\/?p=465"},"modified":"2020-05-09T15:55:31","modified_gmt":"2020-05-09T06:55:31","slug":"unity5%e3%81%a7navmeshagent%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%9f%e6%95%b5%e3%81%ae%e4%bd%93%e5%bd%93%e3%81%9f%e3%82%8a%e3%81%a8%e6%94%bb%e6%92%83%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/hajimete-program.com\/blog\/2016\/07\/27\/unity5%e3%81%a7navmeshagent%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%9f%e6%95%b5%e3%81%ae%e4%bd%93%e5%bd%93%e3%81%9f%e3%82%8a%e3%81%a8%e6%94%bb%e6%92%83%e6%96%b9%e6%b3%95\/","title":{"rendered":"Unity5\u3067NavMeshAgent\u3092\u4f7f\u3063\u305f\u6575\u306e\u4f53\u5f53\u305f\u308a\u3068\u653b\u6483\u65b9\u6cd5"},"content":{"rendered":"<p>Sebastian Lague\u3055\u3093\u306eYoutube\u52d5\u753b\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u300c<a href=\"https:\/\/www.youtube.com\/watch?v=njqRlH3Hj3Q\">Unity Create a Game Series (E06. enemy attacks)<\/a>\u300d\u3067Unity\u306e\u30ca\u30d3\u30b2\u30fc\u30b7\u30e7\u30f3\u306e\u4f7f\u3044\u65b9\u304c\u308f\u304b\u308a\u307e\u3057\u305f\u304c\u3001\u3044\u304f\u3064\u304b\u8a08\u7b97\u65b9\u6cd5\u304c\u7406\u89e3\u3067\u304d\u306a\u304b\u3063\u305f\u306e\u3067\u3001\u4eca\u56de\u3082\u5c0f\u3055\u306a\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u3066\u3001\u518d\u5b66\u7fd2\u3057\u307e\u3057\u305f\u3002<\/p>\n<p><iframe loading=\"lazy\" width=\"840\" height=\"473\" src=\"https:\/\/www.youtube.com\/embed\/njqRlH3Hj3Q?feature=oembed\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_73 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69df039508326\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69df039508326\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/hajimete-program.com\/blog\/2016\/07\/27\/unity5%e3%81%a7navmeshagent%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%9f%e6%95%b5%e3%81%ae%e4%bd%93%e5%bd%93%e3%81%9f%e3%82%8a%e3%81%a8%e6%94%bb%e6%92%83%e6%96%b9%e6%b3%95\/#%E6%95%B5%E3%81%8C%E3%83%97%E3%83%AC%E3%82%A4%E3%83%A4%E3%83%BC%E3%81%AB%E7%A7%BB%E5%8B%95%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95\" title=\"\u6575\u304c\u30d7\u30ec\u30a4\u30e4\u30fc\u306b\u79fb\u52d5\u3059\u308b\u65b9\u6cd5\">\u6575\u304c\u30d7\u30ec\u30a4\u30e4\u30fc\u306b\u79fb\u52d5\u3059\u308b\u65b9\u6cd5<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/hajimete-program.com\/blog\/2016\/07\/27\/unity5%e3%81%a7navmeshagent%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%9f%e6%95%b5%e3%81%ae%e4%bd%93%e5%bd%93%e3%81%9f%e3%82%8a%e3%81%a8%e6%94%bb%e6%92%83%e6%96%b9%e6%b3%95\/#%E4%B8%80%E5%AE%9A%E3%81%AE%E8%B7%9D%E9%9B%A2%E3%82%92%E4%BF%9D%E3%81%A4%E6%96%B9%E6%B3%95\" title=\"\u4e00\u5b9a\u306e\u8ddd\u96e2\u3092\u4fdd\u3064\u65b9\u6cd5\">\u4e00\u5b9a\u306e\u8ddd\u96e2\u3092\u4fdd\u3064\u65b9\u6cd5<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/hajimete-program.com\/blog\/2016\/07\/27\/unity5%e3%81%a7navmeshagent%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%9f%e6%95%b5%e3%81%ae%e4%bd%93%e5%bd%93%e3%81%9f%e3%82%8a%e3%81%a8%e6%94%bb%e6%92%83%e6%96%b9%e6%b3%95\/#%E6%95%B5%E3%81%8C%E6%94%BB%E6%92%83%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95\" title=\"\u6575\u304c\u653b\u6483\u3059\u308b\u65b9\u6cd5\">\u6575\u304c\u653b\u6483\u3059\u308b\u65b9\u6cd5<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/hajimete-program.com\/blog\/2016\/07\/27\/unity5%e3%81%a7navmeshagent%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%9f%e6%95%b5%e3%81%ae%e4%bd%93%e5%bd%93%e3%81%9f%e3%82%8a%e3%81%a8%e6%94%bb%e6%92%83%e6%96%b9%e6%b3%95\/#%E5%B9%B3%E6%96%B9%E6%A0%B9%E3%82%92%E5%9B%9E%E9%81%BF%E3%81%97%E3%81%A6%E3%83%91%E3%83%95%E3%82%A9%E3%83%BC%E3%83%9E%E3%83%B3%E3%82%B9%E3%82%92%E3%82%88%E3%81%8F%E3%81%99%E3%82%8B\" title=\"\u5e73\u65b9\u6839\u3092\u56de\u907f\u3057\u3066\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u3088\u304f\u3059\u308b\">\u5e73\u65b9\u6839\u3092\u56de\u907f\u3057\u3066\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u3088\u304f\u3059\u308b<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/hajimete-program.com\/blog\/2016\/07\/27\/unity5%e3%81%a7navmeshagent%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%9f%e6%95%b5%e3%81%ae%e4%bd%93%e5%bd%93%e3%81%9f%e3%82%8a%e3%81%a8%e6%94%bb%e6%92%83%e6%96%b9%e6%b3%95\/#%E3%81%93%E3%81%AE%E3%83%97%E3%83%AD%E3%82%B8%E3%82%A7%E3%82%AF%E3%83%88%E3%81%AE%E9%85%8D%E5%B8%83\" title=\"\u3053\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u914d\u5e03\">\u3053\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u914d\u5e03<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/hajimete-program.com\/blog\/2016\/07\/27\/unity5%e3%81%a7navmeshagent%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%9f%e6%95%b5%e3%81%ae%e4%bd%93%e5%bd%93%e3%81%9f%e3%82%8a%e3%81%a8%e6%94%bb%e6%92%83%e6%96%b9%e6%b3%95\/#%E4%BF%AE%E6%AD%A3%E6%A1%88\" title=\"\u4fee\u6b63\u6848\">\u4fee\u6b63\u6848<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/hajimete-program.com\/blog\/2016\/07\/27\/unity5%e3%81%a7navmeshagent%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%9f%e6%95%b5%e3%81%ae%e4%bd%93%e5%bd%93%e3%81%9f%e3%82%8a%e3%81%a8%e6%94%bb%e6%92%83%e6%96%b9%e6%b3%95\/#%E3%81%BE%E3%81%A8%E3%82%81\" title=\"\u307e\u3068\u3081\">\u307e\u3068\u3081<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"%E6%95%B5%E3%81%8C%E3%83%97%E3%83%AC%E3%82%A4%E3%83%A4%E3%83%BC%E3%81%AB%E7%A7%BB%E5%8B%95%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95\"><\/span>\u6575\u304c\u30d7\u30ec\u30a4\u30e4\u30fc\u306b\u79fb\u52d5\u3059\u308b\u65b9\u6cd5<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u3053\u308c\u306fUnity\u306e\u30ca\u30d3\u30b2\u30fc\u30b7\u30e7\u30f3\u3092\u4f7f\u3048\u3070\u7c21\u5358\u3067\u3059\u3002<\/p>\n<pre class=\"toolbar:1 lang:c# decode:true\">\t\t\t\/\/ \u30bf\u30fc\u30b2\u30c3\u30c8\u306e\u4e2d\u5fc3\u306b\u307e\u3067\u79fb\u52d5\u3059\u308b\r\n\t\t\tVector3 targetPosition = new Vector3(target.position.x, 0f, target.position.z);\r\n\t\t\tagent.SetDestination(targetPosition);\r\n<\/pre>\n<p>\u6575\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306bNavMeshAgent\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u30a4\u30f3\u30b9\u30da\u30af\u30bf\u30fc\u3067\u6301\u305f\u305b\u3066\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u4e0a\u3067\u306f\u3001agent = GetComponent&lt;NavMeshAgent&gt;();\u3067\u5909\u6570\u306b\u4fdd\u6301\u3057\u3066\u3001agent.SetDestination(\u5ea7\u6a19);\u3067\u3001\u6575\u304c\u969c\u5bb3\u7269\u3092\u4ea4\u308f\u3057\u306a\u304c\u3089\u79fb\u52d5\u3059\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3067\u3059\u304cCollider\u3092\u7121\u52b9\u306b\u3057\u305f\u5834\u5408\u306b\u306f\u3001\u30d7\u30ec\u30a4\u30e4\u30fc\u306e\u4e2d\u5fc3\u5ea7\u6a19\u304c\u3001\u30ca\u30d3\u30b2\u30fc\u30b7\u30e7\u30f3\u306e\u5230\u9054\u4f4d\u7f6e\u306a\u306e\u3067\u3001\u30d7\u30ec\u30a4\u30e4\u30fc\u306b\u57cb\u307e\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<figure id=\"attachment_467\" aria-describedby=\"caption-attachment-467\" style=\"width: 580px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-467 size-full\" src=\"https:\/\/hajimete-program.com\/blog\/wp-content\/uploads\/2016\/07\/002-17.png\" alt=\"002\" width=\"580\" height=\"397\" srcset=\"https:\/\/hajimete-program.com\/blog\/wp-content\/uploads\/2016\/07\/002-17.png 580w, https:\/\/hajimete-program.com\/blog\/wp-content\/uploads\/2016\/07\/002-17-300x205.png 300w\" sizes=\"auto, (max-width: 580px) 85vw, 580px\" \/><figcaption id=\"caption-attachment-467\" class=\"wp-caption-text\">Collider\u304c\u7121\u52b9\u306a\u305f\u3081\u3001\u6575\u304c\u57cb\u307e\u3063\u3066\u3057\u307e\u3046\u4f8b<\/figcaption><\/figure>\n<p>\u3082\u3061\u308d\u3093Collider\u3092\u6709\u52b9\u306b\u3057\u3066\u3044\u308b\u5834\u5408\u306f\u6b63\u3057\u304f\u885d\u7a81\u3057\u307e\u3059\u3002\u305f\u3060\u30b2\u30fc\u30e0\u3067\u306f\u3001\u4f53\u5f53\u305f\u308a\u3059\u308b\u6575\u3082\u3044\u307e\u3059\u304c\u3001\u30d7\u30ec\u30a4\u30e4\u30fc\u306e\u81f3\u8fd1\u8ddd\u96e2\u307e\u3067\u6765\u3066\u3001\u6b66\u5668\u3084\u9b54\u6cd5\u3092\u632f\u308a\u56de\u3059\u3088\u3046\u306a\u6575\u3082\u3044\u307e\u3059\u3002\u3053\u306e\u3088\u3046\u306a\u5834\u5408\u3001\u4f55\u3089\u304b\u306e\u65b9\u6cd5\u3067\u4e00\u5b9a\u306e\u8ddd\u96e2\u3092\u4fdd\u3064\u8a08\u7b97\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E4%B8%80%E5%AE%9A%E3%81%AE%E8%B7%9D%E9%9B%A2%E3%82%92%E4%BF%9D%E3%81%A4%E6%96%B9%E6%B3%95\"><\/span>\u4e00\u5b9a\u306e\u8ddd\u96e2\u3092\u4fdd\u3064\u65b9\u6cd5<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre class=\"toolbar:1 lang:c# decode:true\">agent.SetDestination(targetPosition);<\/pre>\n<p>\u5148\u307b\u3069\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3067\u306f\u3001\u30bf\u30fc\u30b2\u30c3\u30c8\u306e\u4e2d\u5fc3\u4f4d\u7f6e\u306a\u306e\u3067\u3001\u30bf\u30fc\u30b2\u30c3\u30c8\u306b\u57cb\u307e\u3063\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u3002\u306a\u306e\u3067\u885d\u7a81\u5224\u5b9a\u306e\u534a\u5f84\u3092\u8003\u616e\u3059\u308c\u3070\u3088\u3044\u3067\u3059\u3002<\/p>\n<ol>\n<li>\u6575\u304c\u30d7\u30ec\u30a4\u30e4\u30fc\u306b\u5411\u304b\u3046\u65b9\u5411\u3092\u6c42\u3081\u308b<\/li>\n<li>\u30bf\u30fc\u30b2\u30c3\u30c8\u306e\u4f4d\u7f6e\u304b\u3089\u3001(\u30bf\u30fc\u30b2\u30c3\u30c8\u306e\u885d\u7a81\u5224\u5b9a\u306e\u534a\u5f84+\u6575\u81ea\u8eab\u306e\u885d\u7a81\u5224\u5b9a\u306e\u534a\u5f84)*\u5411\u304b\u3046\u65b9\u5411\u3092\u5f15\u304f<\/li>\n<\/ol>\n<pre class=\"toolbar:1 lang:c# decode:true\">\tIEnumerator UpdatePath() \r\n\t{\r\n\t\twhile (target != null) {\r\n\r\n\t\t\t\/\/ \u65b9\u5411\u3092\u6c42\u3081\u308b\r\n\t\t\tVector3 directionToTarget = (target.position - transform.position).normalized;\r\n\t\t\t\/\/ directionToTarget * (\u81ea\u5206\u306e\u534a\u5f84+\u30bf\u30fc\u30b2\u30c3\u30c8\u306e\u534a\u5f84)\u3067\u3001\u81ea\u5206\u3068\u30bf\u30fc\u30b2\u30c3\u30c8\u306e\u534a\u5f84\u306e\u9577\u3055\u5206\u306e\u5411\u304d\u30d9\u30af\u30c8\u30eb\u304c\u6c42\u3081\u3089\u308c\u308b\u3002\r\n\t\t\t\/\/ \u3064\u307e\u308a\u3001\u5143\u3005\u306e\u30bf\u30fc\u30b2\u30c3\u30c8\u5ea7\u6a19\u304b\u3089\u3001\u3053\u306e\u9577\u3055\u306e\u30d9\u30af\u30c8\u30eb\u3092\u5f15\u3051\u3070\u3001\u30bf\u30fc\u30b2\u30c3\u30c8\u306b\u91cd\u306a\u3089\u306a\u3044\u3002\u307e\u305f\u3001\u30de\u30fc\u30b8\u30f3\u3068\u3057\u3066attackDistanceThreshold\u3092\u7528\u610f\u3057\u3066\u3044\u308b\u3002\r\n\t\t\tVector3 targetPosition = target.position - directionToTarget * (myCollisionRadius + targetCollisionRadius + attackDistanceThreshold \/ 2);\r\n\t\t\tagent.SetDestination(targetPosition);\r\n\t\t\t\r\n\r\n\t\t\t\/\/ \uff11\u79d2\u30a6\u30a7\u30a4\u30c8\r\n\t\t\tyield return new WaitForSeconds(.5f);\r\n\t\t}\r\n\t}\r\n<\/pre>\n<figure id=\"attachment_469\" aria-describedby=\"caption-attachment-469\" style=\"width: 553px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-469\" src=\"https:\/\/hajimete-program.com\/blog\/wp-content\/uploads\/2016\/07\/003-10.png\" alt=\"\u7d2b\u306e\u6575\u304c\u3001\u8d64\u306e\u30d7\u30ec\u30a4\u30e4\u30fc\u306b\u63a5\u89e6\u305b\u305a\u306b\u3068\u3069\u307e\u308b\" width=\"553\" height=\"435\" srcset=\"https:\/\/hajimete-program.com\/blog\/wp-content\/uploads\/2016\/07\/003-10.png 553w, https:\/\/hajimete-program.com\/blog\/wp-content\/uploads\/2016\/07\/003-10-300x236.png 300w\" sizes=\"auto, (max-width: 553px) 85vw, 553px\" \/><figcaption id=\"caption-attachment-469\" class=\"wp-caption-text\">\u7d2b\u306e\u6575\u304c\u3001\u8d64\u306e\u30d7\u30ec\u30a4\u30e4\u30fc\u306b\u63a5\u89e6\u305b\u305a\u306b\u3068\u3069\u307e\u308b<\/figcaption><\/figure>\n<p>\u3053\u306e\u4ed5\u7d44\u307f\u306f\u3001Unity\u306b\u9650\u3089\u305a\u30b7\u30e5\u30fc\u30c6\u30a3\u30f3\u30b0\u30b2\u30fc\u30e0\u3084\u3082\u3063\u3068\u5358\u7d14\u306a\u30b2\u30fc\u30e0\u3067\u3082\u30aa\u30d5\u30bb\u30c3\u30c8\u8a08\u7b97\u306a\u3069\u3067\u3088\u304f\u4f7f\u308f\u308c\u307e\u3059\u3002\u3064\u307e\u308a<strong>\u30bf\u30fc\u30b2\u30c3\u30c8\u5ea7\u6a19-offset<\/strong>\u3092\u3057\u3066\u3044\u308b\u3060\u3051\u3067\u3059\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E6%95%B5%E3%81%8C%E6%94%BB%E6%92%83%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95\"><\/span>\u6575\u304c\u653b\u6483\u3059\u308b\u65b9\u6cd5<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u5148\u307b\u3069\u3084\u308a\u304b\u305f\u3067\u6575\u304c\u4e00\u5b9a\u8ddd\u96e2\u307e\u3067\u8fd1\u3065\u304f\u3088\u3046\u306b\u3067\u304d\u307e\u3057\u305f\u3002\u6575\u304c\u653b\u6483\u3059\u308b\u65b9\u6cd5\u3082\u540c\u69d8\u3067\u3001\u3055\u3089\u306b\u624b\u524d\u306e\u7bc4\u56f2\u3067\u653b\u6483\u3092\u7e70\u308a\u51fa\u3059\u3088\u3046\u306b\u3057\u307e\u3059\u3002\u57fa\u672c\u7684\u306a\u8003\u3048\u65b9\u306f\u3001<strong>\u73fe\u5728\u306e\u30d7\u30ec\u30a4\u30e4\u30fc\u3068\u6575\u306e\u8ddd\u96e2 &lt; \u653b\u6483\u958b\u59cb\u306e\u8ddd\u96e2\u3000<\/strong>\u304c\u6210\u308a\u7acb\u3063\u305f\u3089\u653b\u6483\u3092\u958b\u59cb\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E5%B9%B3%E6%96%B9%E6%A0%B9%E3%82%92%E5%9B%9E%E9%81%BF%E3%81%97%E3%81%A6%E3%83%91%E3%83%95%E3%82%A9%E3%83%BC%E3%83%9E%E3%83%B3%E3%82%B9%E3%82%92%E3%82%88%E3%81%8F%E3%81%99%E3%82%8B\"><\/span>\u5e73\u65b9\u6839\u3092\u56de\u907f\u3057\u3066\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u3088\u304f\u3059\u308b<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u6570\u5b66\u3067\u306f\u3001\u4e8c\u70b9AB\u306e\u9577\u3055\u3092\u6c42\u3081\u308b\u306b\u306f\u3001\u4e09\u5e73\u65b9\u306e\u5b9a\u7406\u306b\u3088\u308aA*A+B*B=C*C\u306e\u5e73\u65b9\u6839\u3092\u6c42\u3081\u307e\u3059\u3002\u5148\u307b\u3069\u306e\u300c\u8ddd\u96e2A&lt;\u8ddd\u96e2B\u300d\u306e\u3088\u3046\u306b\uff12\u3064\u306e\u9577\u3055\u3092\u6c42\u3081\u3066\u6bd4\u8f03\u3059\u308b\u5834\u5408\u306f\u3001\uff12\u56de\u5e73\u65b9\u6839\u306e\u51e6\u7406\u3092\u3057\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3002\u3057\u304b\u3057\u3001\u5c0f\u6570\u70b9\u306e\u5e73\u65b9\u6839\u3092\u6c42\u3081\u308b\u51e6\u7406\u306f\u91cd\u305f\u3044\u51e6\u7406\u306a\u305f\u3081\u51fa\u6765\u308c\u3070\u907f\u3051\u305f\u3044\u3067\u3059\u3002\u305d\u306e\u305f\u3081\u306e\u30c6\u30af\u30cb\u30c3\u30af\u3068\u3057\u3066\u306f\u3001\u300c\u8ddd\u96e2A&lt;\u8ddd\u96e2B\u300d\u306e\u6bd4\u8f03\u3092\u300c\u8ddd\u96e2A*\u8ddd\u96e2A &lt;\u00a0\u8ddd\u96e2B*\u8ddd\u96e2B\u300d\u3068\u3057\u3066\u3001<strong>\u4e8c\u4e57\u306e\u307e\u307e\u3067\u8a08\u7b97\u3057\u307e\u3059\u3002<\/strong><\/p>\n<p><strong>\u73fe\u5728\u306e\u30d7\u30ec\u30a4\u30e4\u30fc\u3068\u6575\u306e\u8ddd\u96e2\u306e\u4e8c\u4e57 &lt; \u653b\u6483\u958b\u59cb\u306e\u8ddd\u96e2\u306e\u4e8c\u4e57<\/strong><\/p>\n<p>\u3053\u306e\u30c6\u30af\u30cb\u30c3\u30af\u3092\u4f7f\u3046\u305f\u3081\u306bUnity\u3067\u306fsqrMagnitude\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u3066\u3001\u30d9\u30af\u30c8\u30eb\u578b(Vector3)\u304b\u3089\u4e8c\u4e57\u306e\u5024\u304c\u7c21\u5358\u306b\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"toolbar:1 lang:c# decode:true\">\t\t\t\/\/ \u73fe\u5728\u306e\u30bf\u30fc\u30b2\u30c3\u30c8\u3068\u81ea\u8eab\u306e\u8ddd\u96e2\u306e\u4e8c\u4e57\u3002\r\n\t\t\tfloat sqrMag = (target.position - transform.position).sqrMagnitude;\r\n<\/pre>\n<p>\u3053\u306e\u4e8c\u4e57\u306e\u307e\u307e\u8a08\u7b97\u3059\u308b\u30c6\u30af\u30cb\u30c3\u30af\u3092\u77e5\u3063\u3066\u3044\u306a\u3044\u3068\u3001.sqrMagnitude\u304c\u51fa\u3066\u304d\u305f\u308a\u3001Mathf.Pow(\u9577\u3055\u30012)\u304c\u51fa\u3066\u304f\u308b\u610f\u5473\u304c\u7406\u89e3\u3067\u304d\u307e\u305b\u3093\u3002\u3053\u308c\u306f\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306e\u305f\u3081\u3067\u3042\u3063\u3066\u3001\u672c\u6765\u306f\uff12\u3064\u306e\u9577\u3055\u306e\u6bd4\u8f03\u3092\u3057\u305f\u3044\u3060\u3051\u3067\u3059\u3002<\/p>\n<pre class=\"toolbar:1 lang:c# decode:true \">\tvoid Update () {\r\n\t\t\/\/ Time.time\u306f\u30b2\u30fc\u30e0\u958b\u59cb\u304b\u3089\u306e\u79d2\u3002\r\n\t\tif (Time.time &gt; nextAttackTime) {\r\n\t\t\t\/\/ http:\/\/docs.unity3d.com\/jp\/current\/ScriptReference\/Vector3-sqrMagnitude.html\r\n\t\t\t\/\/ \u8ddd\u96e2\u3092\u6bd4\u8f03\u3059\u308b\u3068\u304d\u306f\u3001\u5e73\u65b9\u6839(Mathf.Sqrt)\u306e\u30b3\u30b9\u30c8\u304c\u9ad8\u3044\u306e\u3067\u3001\u8ddd\u96e2\u306e\u4e8c\u4e57\u901a\u3057\u3092\u8a08\u7b97\u3059\u308b\u3053\u3068\u3067\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u3042\u3052\u308b\u3002\r\n\t\t\t\/\/ \u73fe\u5728\u306e\u30bf\u30fc\u30b2\u30c3\u30c8\u3068\u81ea\u8eab\u306e\u8ddd\u96e2\u306e\u4e8c\u4e57\u3002\r\n\t\t\tfloat sqrMag = (target.position - transform.position).sqrMagnitude;\r\n\t\t\t\/\/ \u653b\u6483\u958b\u59cb\u306e\u95be\u5024\u306e\u4e8c\u4e57\r\n\t\t\tfloat sqrAttackRange = Mathf.Pow(myCollisionRadius + targetCollisionRadius + attackDistanceThreshold, 2);\r\n\t\t\tif (sqrMag &lt; sqrAttackRange) {\r\n\t\t\t\tnextAttackTime = Time.time + timeBetweenAttacks;\r\n\t\t\t\tDebug.Log(\"Attack\");\r\n\t\t\t}\r\n\t\t}\r\n\t}<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"%E3%81%93%E3%81%AE%E3%83%97%E3%83%AD%E3%82%B8%E3%82%A7%E3%82%AF%E3%83%88%E3%81%AE%E9%85%8D%E5%B8%83\"><\/span>\u3053\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u914d\u5e03<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><a href=\"https:\/\/hajimete-program.com\/games\/Topdown Shooting A02 enemy attacks.zip\">https:\/\/hajimete-program.com\/games\/Topdown Shooting A02 enemy attacks.zip<\/a><\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E4%BF%AE%E6%AD%A3%E6%A1%88\"><\/span>\u4fee\u6b63\u6848<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Sebastian Lague\u3055\u3093\u306e\u4ed5\u7d44\u307f\u306f\u3001Unity\u3060\u3051\u3067\u306f\u306a\u304f\u3044\u308d\u3093\u306a\u30b2\u30fc\u30e0\u3067\u4f7f\u3048\u308b\u65b9\u6cd5\u3067\u3059\u3002\u3067\u3059\u304cUnity\u306e\u5834\u5408\u30b2\u30fc\u30e0\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5b50\u8981\u7d20\u3092\u7528\u610f\u3057\u3001\u305d\u3053\u306bCollider\u3092\u6301\u305f\u305b\u3001IsTrigger\u306b\u3088\u308a\u3001\u30c8\u30ea\u30ac\u30fc\u30a4\u30d9\u30f3\u30c8\u3067\u3001\u885d\u7a81\u5224\u5b9a\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002\u3053\u306e\u65b9\u6cd5\u306fUnity\u306b\u4f9d\u5b58\u3057\u307e\u3059\u304c\u3001\u3053\u308c\u3067\u653b\u6483\u5224\u5b9a\u3092\u3059\u308b\u3068\u7c21\u5358\u306b\u3067\u304d\u305d\u3046\u306a\u6c17\u304c\u3057\u307e\u3059\u3002<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E3%81%BE%E3%81%A8%E3%82%81\"><\/span>\u307e\u3068\u3081<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u8a08\u7b97\u65b9\u6cd5\u306f\u308f\u304b\u3063\u3066\u3057\u307e\u3048\u3070\u5927\u3057\u305f\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u304c\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u304c\u51fa\u3066\u304d\u305f\u3068\u304d\u306b\u65b9\u5411\u3092\u6c42\u3081\u3066\u3044\u308b\u306e\u304c\u5206\u304b\u3089\u305a\u3001\u306a\u305c.normalized\u304c\u3042\u308b\u306e\u304b\u306a\u3069\u3092\u304d\u306b\u3057\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"toolbar:1 lang:c# decode:true\">Vector3 dirToTarget = (target.position - transform.position).normalized;<\/pre>\n<p>\u307e\u305f\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3067\u3044\u308d\u3044\u308d\u8a66\u3059\u969b\u306b\u3001\u885d\u7a81\u306e\u534a\u5f84\u3067\u5909\u6570\u3092\u4f7f\u308f\u305a\u6570\u5b57\u3092\u30cf\u30fc\u30c9\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3057\u305f\u308a\u3001\u534a\u5f84\u306e\u5909\u6570\u3092\u524a\u9664\u3057\u305f\u308a\u3059\u308b\u3053\u3068\u3067\u3001\u7406\u89e3\u3092\u6df1\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sebastian Lague\u3055\u3093\u306eYoutube\u52d5\u753b\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u300cUnity Create a Game Series (E06. enemy attacks)\u300d\u3067Unity\u306e\u30ca\u30d3\u30b2\u30fc\u30b7\u30e7\u30f3\u306e\u4f7f\u3044\u65b9\u304c\u308f\u304b\u308a\u307e\u3057\u305f\u304c\u3001 &hellip; <a href=\"https:\/\/hajimete-program.com\/blog\/2016\/07\/27\/unity5%e3%81%a7navmeshagent%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%9f%e6%95%b5%e3%81%ae%e4%bd%93%e5%bd%93%e3%81%9f%e3%82%8a%e3%81%a8%e6%94%bb%e6%92%83%e6%96%b9%e6%b3%95\/\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Unity5\u3067NavMeshAgent\u3092\u4f7f\u3063\u305f\u6575\u306e\u4f53\u5f53\u305f\u308a\u3068\u653b\u6483\u65b9\u6cd5&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":466,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48,26,14],"tags":[28,9,49,11],"class_list":["post-465","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-navigation","category-physics","category-unity","tag-3d-","tag-c","tag-navigation","tag-unity"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/hajimete-program.com\/blog\/wp-json\/wp\/v2\/posts\/465","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hajimete-program.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hajimete-program.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hajimete-program.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hajimete-program.com\/blog\/wp-json\/wp\/v2\/comments?post=465"}],"version-history":[{"count":6,"href":"https:\/\/hajimete-program.com\/blog\/wp-json\/wp\/v2\/posts\/465\/revisions"}],"predecessor-version":[{"id":474,"href":"https:\/\/hajimete-program.com\/blog\/wp-json\/wp\/v2\/posts\/465\/revisions\/474"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hajimete-program.com\/blog\/wp-json\/wp\/v2\/media\/466"}],"wp:attachment":[{"href":"https:\/\/hajimete-program.com\/blog\/wp-json\/wp\/v2\/media?parent=465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hajimete-program.com\/blog\/wp-json\/wp\/v2\/categories?post=465"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hajimete-program.com\/blog\/wp-json\/wp\/v2\/tags?post=465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}