{"id":1493,"date":"2012-12-09T13:41:26","date_gmt":"2012-12-09T10:41:26","guid":{"rendered":"http:\/\/unitycoder.com\/blog\/?p=1493"},"modified":"2013-09-12T20:19:27","modified_gmt":"2013-09-12T17:19:27","slug":"enemy-visibility-cone","status":"publish","type":"post","link":"https:\/\/unitycoder.com\/blog\/2012\/12\/09\/enemy-visibility-cone\/","title":{"rendered":"Enemy Visibility Cone (idea)"},"content":{"rendered":"<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1494\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2012\/12\/09\/enemy-visibility-cone\/npc_venemy_iew_cone\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/12\/npc_venemy_iew_cone.jpg?fit=680%2C680&amp;ssl=1\" data-orig-size=\"680,680\" 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;}\" data-image-title=\"npc_enemy_iew_cone\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/12\/npc_venemy_iew_cone.jpg?fit=680%2C680&amp;ssl=1\" class=\"alignnone size-full wp-image-1494\" title=\"npc_enemy_iew_cone\" alt=\"\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/12\/npc_venemy_iew_cone.jpg?resize=680%2C680\" width=\"680\" height=\"680\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/12\/npc_venemy_iew_cone.jpg?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/12\/npc_venemy_iew_cone.jpg?resize=150%2C150&amp;ssl=1 150w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/12\/npc_venemy_iew_cone.jpg?resize=300%2C300&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/p>\n<p>Testing one visibility cone idea for enemies. (later will check what other solutions there are..)<\/p>\n<p><strong>Code:<\/strong><\/p>\n<ol>\n<li>If enemy stays inside blue trigger area (attached to player) then\n<ol>\n<li>If enemy view angle is towards the player (within view angle range) then\n<ol>\n<li>Do Linecast(s) to player bounding circle\/sphere then\n<ol>\n<li>if LineCast doesn&#8217;t hit obstacles, we can see the player<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>Now just need to try that in Unity..<\/p>\n<p><strong>Version 1.0<\/strong> <strong>notes<\/strong><br \/>\n&#8211; <a title=\"http:\/\/docs.unity3d.com\/Documentation\/ScriptReference\/Vector3.Dot.html\" href=\"http:\/\/docs.unity3d.com\/Documentation\/ScriptReference\/Vector3.Dot.html\" target=\"_blank\">Vector3.Dot<\/a> used to check if player is front of the enemy (theres ready code in docs)<br \/>\n&#8211; <a title=\"http:\/\/docs.unity3d.com\/Documentation\/ScriptReference\/Physics.Linecast.html\" href=\"http:\/\/docs.unity3d.com\/Documentation\/ScriptReference\/Physics.Linecast.html\" target=\"_blank\">Physics.LineCast<\/a> for checking if there are any walls between player-enemy<br \/>\n&#8211; <a title=\"http:\/\/docs.unity3d.com\/Documentation\/ScriptReference\/Quaternion.LookRotation.html\" href=\"http:\/\/docs.unity3d.com\/Documentation\/ScriptReference\/Quaternion.LookRotation.html\" target=\"_blank\">Quaternion.LookRotation<\/a> &amp; <a title=\"http:\/\/docs.unity3d.com\/Documentation\/ScriptReference\/Quaternion.Slerp.html\" href=\"http:\/\/docs.unity3d.com\/Documentation\/ScriptReference\/Quaternion.Slerp.html\" target=\"_blank\">Quaternion.Slerp<\/a> for rotating &amp; turning towards the player<br \/>\n&#8211; <a title=\"http:\/\/docs.unity3d.com\/Documentation\/ScriptReference\/Vector3.MoveTowards.html\" href=\"http:\/\/docs.unity3d.com\/Documentation\/ScriptReference\/Vector3.MoveTowards.html\" target=\"_blank\">Vector3.MoveTowards<\/a> for moving towards player<\/p>\n<p><strong>Webplayer:<\/strong><br \/>\n<a title=\"start webplayer demo\" href=\"http:\/\/unitycoder.com\/upload\/demos\/EnemyVisibilityCone1\/\" target=\"_blank\">http:\/\/unitycoder.com\/upload\/demos\/EnemyVisibilityCone1\/<\/a> (v1.0)<\/p>\n<p><strong>Download source:<\/strong><br \/>\n<a title=\"Download source\" href=\"http:\/\/unitycoder.com\/download\/index2.php?link=459&amp;uid=un1t3c0d5r\" target=\"_blank\">enemyVision1.unityPackage<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Testing one visibility cone idea for enemies. (later will check what other solutions there are..) Code: If enemy stays inside blue trigger area (attached to player) then If enemy view angle is towards the player (within view angle range) then Do Linecast(s) to player bounding [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1494,"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":[4,3],"tags":[173,379,378,174,280,172],"class_list":["post-1493","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-demos","category-unity3d","tag-cone","tag-enemy","tag-npc","tag-range","tag-view","tag-visibility"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/12\/npc_venemy_iew_cone.jpg?fit=680%2C680&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p1KTaT-o5","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/1493","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=1493"}],"version-history":[{"count":14,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/1493\/revisions"}],"predecessor-version":[{"id":2406,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/1493\/revisions\/2406"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media\/1494"}],"wp:attachment":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media?parent=1493"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/categories?post=1493"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/tags?post=1493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}