{"id":455037,"date":"2025-04-07T15:01:47","date_gmt":"2025-04-07T15:01:47","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=455037"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=455037","title":{"rendered":"<span>Ursina: \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0443\u043c\u043d\u044b\u0445 NPC \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0435\u0440\u0435\u0432\u044c\u044f (\u0427\u0430\u0441\u0442\u044c 2)<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><a href=\"https:\/\/habr.com\/ru\/articles\/898354\/\" rel=\"noopener noreferrer nofollow\">&lt;&#8212; \u041f\u0440\u043e\u0448\u043b\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f<\/a><\/p>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438 \u043e\u0441\u043d\u043e\u0432\u044b Ursina \u0438 \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u0443\u044e 3D-\u0438\u0433\u0440\u0443. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u043a\u0435 \u2014\u00a0<strong>\u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u043b\u043b\u0435\u043a\u0442\u0443 \u0434\u043b\u044f NPC<\/strong>\u00a0\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e\u00a0<strong>\u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432<\/strong>\u00a0(Behavior Trees).<\/p>\n<hr\/>\n<h3>1. \u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0435\u0440\u0435\u0432\u044c\u044f?<\/h3>\n<p>\u041f\u043e\u0432\u0435\u0434\u0435\u043d\u0447\u0435\u0441\u043a\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e \u2014 \u044d\u0442\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043b\u043e\u0433\u0438\u043a\u0443 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 NPC. \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432, \u043e\u043d\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442:<\/p>\n<ul>\n<li>\n<p><strong>\u0413\u0438\u0431\u043a\u043e \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c<\/strong>\u00a0\u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f<\/p>\n<\/li>\n<li>\n<p><strong>\u041b\u0435\u0433\u043a\u043e \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u0442\u044c<\/strong>\u00a0\u0418\u0418-\u043b\u043e\u0433\u0438\u043a\u0443<\/p>\n<\/li>\n<li>\n<p><strong>\u0418\u0437\u0431\u0435\u0433\u0430\u0442\u044c \u0441\u043f\u0430\u0433\u0435\u0442\u0442\u0438-\u043a\u043e\u0434\u0430<\/strong>\u00a0\u0432 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f\u0445<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430 \u0434\u043b\u044f NPC-\u0441\u0442\u0440\u0430\u0436\u0430:<\/strong><\/p>\n<pre><code>\u041f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043e\u0445\u0440\u0430\u043d\u043d\u0438\u043a\u0430:   \u251c\u2500 \u0415\u0441\u043b\u0438 \u0432\u0438\u0434\u0438\u0442 \u0438\u0433\u0440\u043e\u043a\u0430 \u2192 \u0410\u0442\u0430\u043a\u043e\u0432\u0430\u0442\u044c   \u251c\u2500 \u0415\u0441\u043b\u0438 \u0441\u043b\u044b\u0448\u0438\u0442 \u0448\u0443\u043c \u2192 \u0418\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c   \u2514\u2500 \u0418\u043d\u0430\u0447\u0435 \u2192 \u041f\u0430\u0442\u0440\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c  <\/code><\/pre>\n<hr\/>\n<h3>2. \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c AI \u0432 Ursina<\/h3>\n<p>Ursina \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043c\u043e\u0434\u0443\u043b\u044c\u00a0<strong>Behavior<\/strong>\u00a0\u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u0434\u0435\u0440\u0435\u0432\u044c\u044f\u043c\u0438.<\/p>\n<h4>\u0428\u0430\u0433 1: \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e NPC<\/h4>\n<pre><code>from ursina import *   from ursina.prefabs.ai import Behavior    app = Ursina()    # NPC - \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u0443\u0431 \u0441 \"\u043c\u043e\u0437\u0433\u0430\u043c\u0438\"   npc = Entity(model='cube', color=color.red, position=(3, 0, 0))  <\/code><\/pre>\n<h4>\u0428\u0430\u0433 2: \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h4>\n<pre><code># \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f NPC   def patrol():       npc.x += time.dt * 2  # \u0414\u0432\u0438\u0436\u0435\u0442\u0441\u044f \u0432\u043f\u0440\u0430\u0432\u043e       if npc.x &gt; 5:           npc.x = -5  # \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0441\u0442\u0430\u0440\u0442    def chase_player():       npc.position += (player.position - npc.position).normalized() * time.dt * 3    # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0435\u0440\u0435\u0432\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f   npc.add_script(Behavior({       'sequence': [           {'condition': lambda: distance(npc, player) &lt; 3, 'action': chase_player},           {'action': patrol}       ]   }))  <\/code><\/pre>\n<p><strong>\u041a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442:<\/strong><\/p>\n<ol>\n<li>\n<p>NPC \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0431\u043b\u0438\u0437\u043a\u043e \u043b\u0438 \u0438\u0433\u0440\u043e\u043a (<strong>distance &lt; 3<\/strong>).<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0434\u0430 \u2014 \u043f\u0440\u0435\u0441\u043b\u0435\u0434\u0443\u0435\u0442 (<strong>chase_player<\/strong>).<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0435\u0442 \u2014 \u043f\u0430\u0442\u0440\u0443\u043b\u0438\u0440\u0443\u0435\u0442 (<strong>patrol<\/strong>).<\/p>\n<\/li>\n<\/ol>\n<hr\/>\n<h3>3. \u0421\u043b\u043e\u0436\u043d\u044b\u0435 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438<\/h3>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440: NPC \u0441 \u0442\u0440\u0435\u043c\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u043c\u0438<\/h4>\n<pre><code>states = {       'calm': {           'action': lambda: setattr(npc, 'color', color.green),           'transition': [               {'condition': lambda: distance(npc, player) &lt; 4, 'next_state': 'alert'},           ]       },       'alert': {           'action': lambda: setattr(npc, 'color', color.yellow),           'transition': [               {'condition': lambda: distance(npc, player) &lt; 2, 'next_state': 'angry'},               {'condition': lambda: distance(npc, player) &gt; 5, 'next_state': 'calm'},           ]       },       'angry': {           'action': chase_player,           'transition': [               {'condition': lambda: distance(npc, player) &gt; 4, 'next_state': 'alert'},           ]       }   }    npc.add_script(Behavior({'state_machine': states}))  <\/code><\/pre>\n<p><strong>\u041b\u043e\u0433\u0438\u043a\u0430:<\/strong><\/p>\n<ul>\n<li>\n<p>\ud83d\udfe2\u00a0<strong>\u0421\u043f\u043e\u043a\u043e\u0439\u043d\u044b\u0439<\/strong>\u00a0(\u0437\u0435\u043b\u0435\u043d\u044b\u0439): \u0438\u0433\u0440\u043e\u043a \u0434\u0430\u043b\u0435\u043a\u043e \u2192 NPC \u0441\u0442\u043e\u0438\u0442.<\/p>\n<\/li>\n<li>\n<p>\ud83d\udfe1\u00a0<strong>\u041d\u0430\u0441\u0442\u043e\u0440\u043e\u0436\u0435\u043d\u043d\u044b\u0439<\/strong>\u00a0(\u0436\u0435\u043b\u0442\u044b\u0439): \u0438\u0433\u0440\u043e\u043a \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0430\u0435\u0442\u0441\u044f \u2192 NPC \u043f\u043e\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043a \u043d\u0435\u043c\u0443.<\/p>\n<\/li>\n<li>\n<p>\ud83d\udd34\u00a0<strong>\u0410\u0433\u0440\u0435\u0441\u0441\u0438\u0432\u043d\u044b\u0439<\/strong>\u00a0(\u043a\u0440\u0430\u0441\u043d\u044b\u0439): \u0438\u0433\u0440\u043e\u043a \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0431\u043b\u0438\u0437\u043a\u043e \u2192 \u043f\u043e\u0433\u043e\u043d\u044f!<\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<h3>4. \u041f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0435 \u0442\u0435\u0445\u043d\u0438\u043a\u0438<\/h3>\n<h4>4.1. \u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u043f\u0430\u043c\u044f\u0442\u044c\u044e NPC<\/h4>\n<p>\u0427\u0442\u043e\u0431\u044b NPC &#171;\u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u043b&#187; \u0438\u0433\u0440\u043e\u043a\u0430 \u0434\u0430\u0436\u0435 \u043a\u043e\u0433\u0434\u0430 \u0442\u043e\u0442 \u0441\u043a\u0440\u044b\u043b\u0441\u044f:<\/p>\n<pre><code>npc.memory = {'last_seen_player_pos': None}    def remember_player():       if distance(npc, player) &lt; 3:           npc.memory['last_seen_player_pos'] = player.position    Behavior({       'action': remember_player,       'sequence': [           {'condition': lambda: npc.memory['last_seen_player_pos'] is not None,            'action': lambda: npc.look_at(npc.memory['last_seen_player_pos'])},           {'action': patrol}       ]   })  <\/code><\/pre>\n<h4>4.2. \u0413\u0440\u0443\u043f\u043f\u043e\u0432\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h4>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0442\u0430\u044e NPC, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0430\u0442\u0430\u043a\u0443\u0435\u0442 \u0432\u043c\u0435\u0441\u0442\u0435:<\/p>\n<pre><code>enemies = [Entity(model='cube', color=color.red) for _ in range(5)]    for enemy in enemies:       enemy.add_script(Behavior({           'parallel': [               {'condition': lambda e=enemy: distance(e, player) &lt; 4, 'action': chase_player},               {'action': lambda e=enemy: e.look_at_2d(player)}           ]       }))  <\/code><\/pre>\n<hr\/>\n<h3>5. \u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/h3>\n<ul>\n<li>\n<p><strong>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u00a0distance_squared<\/strong>\u00a0\u0432\u043c\u0435\u0441\u0442\u043e\u00a0<strong>distance<\/strong>\u00a0\u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a (\u0438\u0437\u0431\u0435\u0433\u0430\u0435\u043c \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u043a\u043e\u0440\u043d\u044f).<\/p>\n<\/li>\n<li>\n<p><strong>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0439\u0442\u0435 \u0447\u0430\u0441\u0442\u043e\u0442\u0443 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a<\/strong>\u00a0\u0447\u0435\u0440\u0435\u0437\u00a0<strong>time.dt<\/strong>:<\/p>\n<pre><code>def update():       if time.time() % 1.0 &lt; time.dt:  # \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0440\u0430\u0437 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443           npc.bt.update()  <\/code><\/pre>\n<\/li>\n<\/ul>\n<hr\/>\n<h3>6. \u0427\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435?<\/h3>\n<ol>\n<li>\n<p><strong>\u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u043f\u0443\u0442\u044cfinding<\/strong>\u00a0\u0447\u0435\u0440\u0435\u0437\u00a0<strong>ursina.pathfinding<\/strong>\u00a0\u0434\u043b\u044f \u043e\u0431\u0445\u043e\u0434\u0430 \u043f\u0440\u0435\u043f\u044f\u0442\u0441\u0442\u0432\u0438\u0439.<\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0434\u0438\u0430\u043b\u043e\u0433\u043e\u0432\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443<\/strong>\u00a0\u2014 NPC \u043c\u043e\u0433\u0443\u0442 \u0440\u0435\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u0441\u043b\u043e\u0432\u0430 \u0438\u0433\u0440\u043e\u043a\u0430.<\/p>\n<\/li>\n<li>\n<p><strong>\u042d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0439\u0442\u0435<\/strong>\u00a0\u0441 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044f\u043c\u0438 (\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u0435 TensorFlow \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f NPC).<\/p>\n<\/li>\n<\/ol>\n<blockquote>\n<p><strong>\u0421\u043e\u0432\u0435\u0442:<\/strong>\u00a0\u0414\u043b\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432\u00a0<a href=\"https:\/\/github.com\/mwoolweaver\/BehaviorTreeEditor\" rel=\"noopener noreferrer nofollow\">Behavior Tree Editor<\/a>.<\/p>\n<\/blockquote>\n<p><strong>\u0418\u0442\u043e\u0433:<\/strong>\u00a0\u0421 Ursina \u0434\u0430\u0436\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u0418\u0418 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c. \u041d\u0430\u0447\u043d\u0438\u0442\u0435 \u0441 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043f\u0430\u0442\u0440\u0443\u043b\u0435\u0439, \u0430 \u0437\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0439\u0442\u0435 NPC \u0441 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u043e\u043c!<\/p>\n<p>P.S. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c NPC, \u043a\u043e\u0442\u043e\u0440\u044b\u0439:<\/p>\n<ul>\n<li>\n<p>\u041f\u0440\u044f\u0447\u0435\u0442\u0441\u044f \u0437\u0430 \u0443\u043a\u0440\u044b\u0442\u0438\u044f\u043c\u0438<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u0431\u0438\u0440\u0430\u0435\u0442 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u044b<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u0449\u0430\u0435\u0442\u0441\u044f \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 NPC<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u0430\u043a\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0435 \u043f\u0435\u0440\u0432\u044b\u043c? \ud83d\ude80<\/p>\n<details class=\"spoiler\">\n<summary>\u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0433\u0440\u044b<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">from ursina import * import random  app = Ursina()  # \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0438\u0433\u0440\u044b player_speed = 5 npc_speed = 2.5 collectibles_count = 10 score = 0  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0438\u0433\u0440\u043e\u043a\u0430 player = Entity(     model='cube',     color=color.orange,     scale=(1, 1, 1),     collider='box' )  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0437\u0435\u043c\u043b\u044e ground = Entity(     model='plane',     texture='grass',     scale=(20, 1, 20),     collider='box' )  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c NPC npc = Entity(     model='cube',     color=color.red,     position=(5, 0, 5),     collider='box' )  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u044b\u0435 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u044b collectibles = [] for i in range(collectibles_count):     collectible = Entity(         model='sphere',         color=color.yellow,         scale=0.5,         position=(random.uniform(-8, 8), 0.5, random.uniform(-8, 8)),         collider='sphere'     )     collectibles.append(collectible)  # UI \u0434\u043b\u044f \u0441\u0447\u0435\u0442\u0430 score_text = Text(text=f'Score: {score}', position=(-0.8, 0.4), scale=2)  # \u041b\u043e\u0433\u0438\u043a\u0430 \u0418\u0418 NPC def update_npc():     if distance(npc, player) &lt; 6:         npc.look_at(player)         npc.position += npc.forward * time.dt * npc_speed     else:         npc.rotation_y += 20 * time.dt         npc.position += npc.forward * time.dt * (npc_speed \/ 2)  # \u041a\u0430\u043c\u0435\u0440\u0430 \u0441 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u0443\u0433\u043b\u043e\u043c camera.position = (0, 15, -20)  # \u0412\u044b\u0441\u043e\u0442\u0430 \u0438 \u043e\u0442\u0434\u0430\u043b\u0435\u043d\u0438\u0435 camera.rotation_x = 30          # \u041d\u0430\u043a\u043b\u043e\u043d \u043a\u0430\u043c\u0435\u0440\u044b \u0432\u043d\u0438\u0437  def update():     global score          # \u0414\u0432\u0438\u0436\u0435\u043d\u0438\u0435 \u0438\u0433\u0440\u043e\u043a\u0430     player.x += held_keys['d'] * time.dt * player_speed     player.x -= held_keys['a'] * time.dt * player_speed     player.z += held_keys['w'] * time.dt * player_speed     player.z -= held_keys['s'] * time.dt * player_speed          # \u0412\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u0438\u0433\u0440\u043e\u043a\u0430 (\u0443\u0431\u0440\u0430\u043b\u0438 Q\/E, \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u043c\u0435\u0440\u0430 \u043d\u0435 \"\u0441\u0440\u044b\u0432\u0430\u043b\u0430\u0441\u044c\")          # \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0418\u0418 NPC     update_npc()          # \u041a\u0430\u043c\u0435\u0440\u0430 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0437\u0430 \u0438\u0433\u0440\u043e\u043a\u043e\u043c \u0441 \u043f\u043b\u0430\u0432\u043d\u044b\u043c \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435\u043c     camera.position = (         player.x,          15,                   # \u0424\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0432\u044b\u0441\u043e\u0442\u0430         player.z - 20          # \u041e\u0442\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043f\u043e Z     )     camera.look_at(player)     # \u041a\u0430\u043c\u0435\u0440\u0430 \u0432\u0441\u0435\u0433\u0434\u0430 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0430 \u043d\u0430 \u0438\u0433\u0440\u043e\u043a\u0430          # \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0441\u0431\u043e\u0440\u0430 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043e\u0432     for collectible in collectibles[:]:         if player.intersects(collectible).hit:             collectibles.remove(collectible)             destroy(collectible)             score += 1             score_text.text = f'Score: {score}'                          if random.random() &gt; 0.3:                 new_collectible = Entity(                     model='sphere',                     color=color.yellow,                     scale=0.5,                     position=(random.uniform(-8, 8), 0.5, random.uniform(-8, 8)),                     collider='sphere'                 )                 collectibles.append(new_collectible)          if player.intersects(npc).hit:         print(\"Game Over!\")         application.pause()  app.run()<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/898360\/\"> https:\/\/habr.com\/ru\/articles\/898360\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><a href=\"https:\/\/habr.com\/ru\/articles\/898354\/\" rel=\"noopener noreferrer nofollow\">&lt;&#8212; \u041f\u0440\u043e\u0448\u043b\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f<\/a><\/p>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438 \u043e\u0441\u043d\u043e\u0432\u044b Ursina \u0438 \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u0443\u044e 3D-\u0438\u0433\u0440\u0443. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u043a\u0435 \u2014\u00a0<strong>\u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u043b\u043b\u0435\u043a\u0442\u0443 \u0434\u043b\u044f NPC<\/strong>\u00a0\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e\u00a0<strong>\u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432<\/strong>\u00a0(Behavior Trees).<\/p>\n<hr\/>\n<h3>1. \u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0435\u0440\u0435\u0432\u044c\u044f?<\/h3>\n<p>\u041f\u043e\u0432\u0435\u0434\u0435\u043d\u0447\u0435\u0441\u043a\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e \u2014 \u044d\u0442\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043b\u043e\u0433\u0438\u043a\u0443 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 NPC. \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432, \u043e\u043d\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442:<\/p>\n<ul>\n<li>\n<p><strong>\u0413\u0438\u0431\u043a\u043e \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c<\/strong>\u00a0\u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f<\/p>\n<\/li>\n<li>\n<p><strong>\u041b\u0435\u0433\u043a\u043e \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u0442\u044c<\/strong>\u00a0\u0418\u0418-\u043b\u043e\u0433\u0438\u043a\u0443<\/p>\n<\/li>\n<li>\n<p><strong>\u0418\u0437\u0431\u0435\u0433\u0430\u0442\u044c \u0441\u043f\u0430\u0433\u0435\u0442\u0442\u0438-\u043a\u043e\u0434\u0430<\/strong>\u00a0\u0432 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f\u0445<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430 \u0434\u043b\u044f NPC-\u0441\u0442\u0440\u0430\u0436\u0430:<\/strong><\/p>\n<pre><code>\u041f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043e\u0445\u0440\u0430\u043d\u043d\u0438\u043a\u0430:   \u251c\u2500 \u0415\u0441\u043b\u0438 \u0432\u0438\u0434\u0438\u0442 \u0438\u0433\u0440\u043e\u043a\u0430 \u2192 \u0410\u0442\u0430\u043a\u043e\u0432\u0430\u0442\u044c   \u251c\u2500 \u0415\u0441\u043b\u0438 \u0441\u043b\u044b\u0448\u0438\u0442 \u0448\u0443\u043c \u2192 \u0418\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c   \u2514\u2500 \u0418\u043d\u0430\u0447\u0435 \u2192 \u041f\u0430\u0442\u0440\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c  <\/code><\/pre>\n<hr\/>\n<h3>2. \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c AI \u0432 Ursina<\/h3>\n<p>Ursina \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043c\u043e\u0434\u0443\u043b\u044c\u00a0<strong>Behavior<\/strong>\u00a0\u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u0434\u0435\u0440\u0435\u0432\u044c\u044f\u043c\u0438.<\/p>\n<h4>\u0428\u0430\u0433 1: \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e NPC<\/h4>\n<pre><code>from ursina import *   from ursina.prefabs.ai import Behavior    app = Ursina()    # NPC - \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u0443\u0431 \u0441 \"\u043c\u043e\u0437\u0433\u0430\u043c\u0438\"   npc = Entity(model='cube', color=color.red, position=(3, 0, 0))  <\/code><\/pre>\n<h4>\u0428\u0430\u0433 2: \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h4>\n<pre><code># \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f NPC   def patrol():       npc.x += time.dt * 2  # \u0414\u0432\u0438\u0436\u0435\u0442\u0441\u044f \u0432\u043f\u0440\u0430\u0432\u043e       if npc.x &gt; 5:           npc.x = -5  # \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0441\u0442\u0430\u0440\u0442    def chase_player():       npc.position += (player.position - npc.position).normalized() * time.dt * 3    # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0435\u0440\u0435\u0432\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f   npc.add_script(Behavior({       'sequence': [           {'condition': lambda: distance(npc, player) &lt; 3, 'action': chase_player},           {'action': patrol}       ]   }))  <\/code><\/pre>\n<p><strong>\u041a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442:<\/strong><\/p>\n<ol>\n<li>\n<p>NPC \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0431\u043b\u0438\u0437\u043a\u043e \u043b\u0438 \u0438\u0433\u0440\u043e\u043a (<strong>distance &lt; 3<\/strong>).<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0434\u0430 \u2014 \u043f\u0440\u0435\u0441\u043b\u0435\u0434\u0443\u0435\u0442 (<strong>chase_player<\/strong>).<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0435\u0442 \u2014 \u043f\u0430\u0442\u0440\u0443\u043b\u0438\u0440\u0443\u0435\u0442 (<strong>patrol<\/strong>).<\/p>\n<\/li>\n<\/ol>\n<hr\/>\n<h3>3. \u0421\u043b\u043e\u0436\u043d\u044b\u0435 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438<\/h3>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440: NPC \u0441 \u0442\u0440\u0435\u043c\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u043c\u0438<\/h4>\n<pre><code>states = {       'calm': {           'action': lambda: setattr(npc, 'color', color.green),           'transition': [               {'condition': lambda: distance(npc, player) &lt; 4, 'next_state': 'alert'},           ]       },       'alert': {           'action': lambda: setattr(npc, 'color', color.yellow),           'transition': [               {'condition': lambda: distance(npc, player) &lt; 2, 'next_state': 'angry'},               {'condition': lambda: distance(npc, player) &gt; 5, 'next_state': 'calm'},           ]       },       'angry': {           'action': chase_player,           'transition': [               {'condition': lambda: distance(npc, player) &gt; 4, 'next_state': 'alert'},           ]       }   }    npc.add_script(Behavior({'state_machine': states}))  <\/code><\/pre>\n<p><strong>\u041b\u043e\u0433\u0438\u043a\u0430:<\/strong><\/p>\n<ul>\n<li>\n<p>\ud83d\udfe2\u00a0<strong>\u0421\u043f\u043e\u043a\u043e\u0439\u043d\u044b\u0439<\/strong>\u00a0(\u0437\u0435\u043b\u0435\u043d\u044b\u0439): \u0438\u0433\u0440\u043e\u043a \u0434\u0430\u043b\u0435\u043a\u043e \u2192 NPC \u0441\u0442\u043e\u0438\u0442.<\/p>\n<\/li>\n<li>\n<p>\ud83d\udfe1\u00a0<strong>\u041d\u0430\u0441\u0442\u043e\u0440\u043e\u0436\u0435\u043d\u043d\u044b\u0439<\/strong>\u00a0(\u0436\u0435\u043b\u0442\u044b\u0439): \u0438\u0433\u0440\u043e\u043a \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0430\u0435\u0442\u0441\u044f \u2192 NPC \u043f\u043e\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043a \u043d\u0435\u043c\u0443.<\/p>\n<\/li>\n<li>\n<p>\ud83d\udd34\u00a0<strong>\u0410\u0433\u0440\u0435\u0441\u0441\u0438\u0432\u043d\u044b\u0439<\/strong>\u00a0(\u043a\u0440\u0430\u0441\u043d\u044b\u0439): \u0438\u0433\u0440\u043e\u043a \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0431\u043b\u0438\u0437\u043a\u043e \u2192 \u043f\u043e\u0433\u043e\u043d\u044f!<\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<h3>4. \u041f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0435 \u0442\u0435\u0445\u043d\u0438\u043a\u0438<\/h3>\n<h4>4.1. \u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u043f\u0430\u043c\u044f\u0442\u044c\u044e NPC<\/h4>\n<p>\u0427\u0442\u043e\u0431\u044b NPC &#171;\u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u043b&#187; \u0438\u0433\u0440\u043e\u043a\u0430 \u0434\u0430\u0436\u0435 \u043a\u043e\u0433\u0434\u0430 \u0442\u043e\u0442 \u0441\u043a\u0440\u044b\u043b\u0441\u044f:<\/p>\n<pre><code>npc.memory = {'last_seen_player_pos': None}    def remember_player():       if distance(npc, player) &lt; 3:           npc.memory['last_seen_player_pos'] = player.position    Behavior({       'action': remember_player,       'sequence': [           {'condition': lambda: npc.memory['last_seen_player_pos'] is not None,            'action': lambda: npc.look_at(npc.memory['last_seen_player_pos'])},           {'action': patrol}       ]   })  <\/code><\/pre>\n<h4>4.2. \u0413\u0440\u0443\u043f\u043f\u043e\u0432\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h4>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0442\u0430\u044e NPC, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0430\u0442\u0430\u043a\u0443\u0435\u0442 \u0432\u043c\u0435\u0441\u0442\u0435:<\/p>\n<pre><code>enemies = [Entity(model='cube', color=color.red) for _ in range(5)]    for enemy in enemies:       enemy.add_script(Behavior({           'parallel': [               {'condition': lambda e=enemy: distance(e, player) &lt; 4, 'action': chase_player},               {'action': lambda e=enemy: e.look_at_2d(player)}           ]       }))  <\/code><\/pre>\n<hr\/>\n<h3>5. \u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/h3>\n<ul>\n<li>\n<p><strong>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u00a0distance_squared<\/strong>\u00a0\u0432\u043c\u0435\u0441\u0442\u043e\u00a0<strong>distance<\/strong>\u00a0\u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a (\u0438\u0437\u0431\u0435\u0433\u0430\u0435\u043c \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u043a\u043e\u0440\u043d\u044f).<\/p>\n<\/li>\n<li>\n<p><strong>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0439\u0442\u0435 \u0447\u0430\u0441\u0442\u043e\u0442\u0443 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a<\/strong>\u00a0\u0447\u0435\u0440\u0435\u0437\u00a0<strong>time.dt<\/strong>:<\/p>\n<pre><code>def update():       if time.time() % 1.0 &lt; time.dt:  # \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0440\u0430\u0437 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443           npc.bt.update()  <\/code><\/pre>\n<\/li>\n<\/ul>\n<hr\/>\n<h3>6. \u0427\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435?<\/h3>\n<ol>\n<li>\n<p><strong>\u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u043f\u0443\u0442\u044cfinding<\/strong>\u00a0\u0447\u0435\u0440\u0435\u0437\u00a0<strong>ursina.pathfinding<\/strong>\u00a0\u0434\u043b\u044f \u043e\u0431\u0445\u043e\u0434\u0430 \u043f\u0440\u0435\u043f\u044f\u0442\u0441\u0442\u0432\u0438\u0439.<\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0434\u0438\u0430\u043b\u043e\u0433\u043e\u0432\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443<\/strong>\u00a0\u2014 NPC \u043c\u043e\u0433\u0443\u0442 \u0440\u0435\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u0441\u043b\u043e\u0432\u0430 \u0438\u0433\u0440\u043e\u043a\u0430.<\/p>\n<\/li>\n<li>\n<p><strong>\u042d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0439\u0442\u0435<\/strong>\u00a0\u0441 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044f\u043c\u0438 (\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u0435 TensorFlow \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f NPC).<\/p>\n<\/li>\n<\/ol>\n<blockquote>\n<p><strong>\u0421\u043e\u0432\u0435\u0442:<\/strong>\u00a0\u0414\u043b\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432\u00a0<a href=\"https:\/\/github.com\/mwoolweaver\/BehaviorTreeEditor\" rel=\"noopener noreferrer nofollow\">Behavior Tree Editor<\/a>.<\/p>\n<\/blockquote>\n<p><strong>\u0418\u0442\u043e\u0433:<\/strong>\u00a0\u0421 Ursina \u0434\u0430\u0436\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u0418\u0418 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c. \u041d\u0430\u0447\u043d\u0438\u0442\u0435 \u0441 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043f\u0430\u0442\u0440\u0443\u043b\u0435\u0439, \u0430 \u0437\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0439\u0442\u0435 NPC \u0441 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u043e\u043c!<\/p>\n<p>P.S. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c NPC, \u043a\u043e\u0442\u043e\u0440\u044b\u0439:<\/p>\n<ul>\n<li>\n<p>\u041f\u0440\u044f\u0447\u0435\u0442\u0441\u044f \u0437\u0430 \u0443\u043a\u0440\u044b\u0442\u0438\u044f\u043c\u0438<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u0431\u0438\u0440\u0430\u0435\u0442 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u044b<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u0449\u0430\u0435\u0442\u0441\u044f \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 NPC<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u0430\u043a\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0435 \u043f\u0435\u0440\u0432\u044b\u043c? \ud83d\ude80<\/p>\n<details class=\"spoiler\">\n<summary>\u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0433\u0440\u044b<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">from ursina import * import random  app = Ursina()  # \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0438\u0433\u0440\u044b player_speed = 5 npc_speed = 2.5 collectibles_count = 10 score = 0  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0438\u0433\u0440\u043e\u043a\u0430 player = Entity(     model='cube',     color=color.orange,     scale=(1, 1, 1),     collider='box' )  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0437\u0435\u043c\u043b\u044e ground = Entity(     model='plane',     texture='grass',     scale=(20, 1, 20),     collider='box' )  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c NPC npc = Entity(     model='cube',     color=color.red,     position=(5, 0, 5),     collider='box' )  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u044b\u0435 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u044b collectibles = [] for i in range(collectibles_count):     collectible = Entity(         model='sphere',         color=color.yellow,         scale=0.5,         position=(random.uniform(-8, 8), 0.5, random.uniform(-8, 8)),         collider='sphere'     )     collectibles.append(collectible)  # UI \u0434\u043b\u044f \u0441\u0447\u0435\u0442\u0430 score_text = Text(text=f'Score: {score}', position=(-0.8, 0.4), scale=2)  # \u041b\u043e\u0433\u0438\u043a\u0430 \u0418\u0418 NPC def update_npc():     if distance(npc, player) &lt; 6:         npc.look_at(player)         npc.position += npc.forward * time.dt * npc_speed     else:         npc.rotation_y += 20 * time.dt         npc.position += npc.forward * time.dt * (npc_speed \/ 2)  # \u041a\u0430\u043c\u0435\u0440\u0430 \u0441 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u0443\u0433\u043b\u043e\u043c camera.position = (0, 15, -20)  # \u0412\u044b\u0441\u043e\u0442\u0430 \u0438 \u043e\u0442\u0434\u0430\u043b\u0435\u043d\u0438\u0435 camera.rotation_x = 30          # \u041d\u0430\u043a\u043b\u043e\u043d \u043a\u0430\u043c\u0435\u0440\u044b \u0432\u043d\u0438\u0437  def update():     global score          # \u0414\u0432\u0438\u0436\u0435\u043d\u0438\u0435 \u0438\u0433\u0440\u043e\u043a\u0430     player.x += held_keys['d'] * time.dt * player_speed     player.x -= held_keys['a'] * time.dt * player_speed     player.z += held_keys['w'] * time.dt * player_speed     player.z -= held_keys['s'] * time.dt * player_speed          # \u0412\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u0438\u0433\u0440\u043e\u043a\u0430 (\u0443\u0431\u0440\u0430\u043b\u0438 Q\/E, \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u043c\u0435\u0440\u0430 \u043d\u0435 \"\u0441\u0440\u044b\u0432\u0430\u043b\u0430\u0441\u044c\")          # \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0418\u0418 NPC     update_npc()          # \u041a\u0430\u043c\u0435\u0440\u0430 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0437\u0430 \u0438\u0433\u0440\u043e\u043a\u043e\u043c \u0441 \u043f\u043b\u0430\u0432\u043d\u044b\u043c \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435\u043c     camera.position = (         player.x,          15,                   # \u0424\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0432\u044b\u0441\u043e\u0442\u0430         player.z - 20          # \u041e\u0442\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043f\u043e Z     )     camera.look_at(player)     # \u041a\u0430\u043c\u0435\u0440\u0430 \u0432\u0441\u0435\u0433\u0434\u0430 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0430 \u043d\u0430 \u0438\u0433\u0440\u043e\u043a\u0430          # \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0441\u0431\u043e\u0440\u0430 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043e\u0432     for collectible in collectibles[:]:         if player.intersects(collectible).hit:             collectibles.remove(collectible)             destroy(collectible)             score += 1             score_text.text = f'Score: {score}'                          if random.random() &gt; 0.3:                 new_collectible = Entity(                     model='sphere',                     color=color.yellow,                     scale=0.5,                     position=(random.uniform(-8, 8), 0.5, random.uniform(-8, 8)),                     collider='sphere'                 )                 collectibles.append(new_collectible)          if player.intersects(npc).hit:         print(\"Game Over!\")         application.pause()  app.run()<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/898360\/\"> https:\/\/habr.com\/ru\/articles\/898360\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-455037","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/455037","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=455037"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/455037\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=455037"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=455037"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=455037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}