<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>AI/Behavior on Godot 4 レシピ</title><link>https://kamera25.github.io/godot_recipes/4.x/ai/index.html</link><description>Recent content in AI/Behavior on Godot 4 レシピ</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="https://kamera25.github.io/godot_recipes/4.x/ai/index.xml" rel="self" type="application/rss+xml"/><item><title>Chasing the player</title><link>https://kamera25.github.io/godot_recipes/4.x/ai/chasing/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/ai/chasing/index.html</guid><description>&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;p&gt;You want an enemy to chase the player.&lt;/p&gt;
&lt;h2 id="solution"&gt;Solution&lt;/h2&gt;
&lt;p&gt;The first step in getting an enemy to chase the player is to determine what direction the enemy needs to move. To get the vector pointing from &lt;strong&gt;A&lt;/strong&gt; to &lt;strong&gt;B&lt;/strong&gt;, you subtract: &lt;strong&gt;B&lt;/strong&gt; - &lt;strong&gt;A&lt;/strong&gt;. Normalize the result and you have a direction vector.&lt;/p&gt;
&lt;p&gt;This makes the solution quite straightforward. Every frame, set the enemy&amp;rsquo;s velocity to point in the direction of the player.&lt;/p&gt;</description></item><item><title>Path following</title><link>https://kamera25.github.io/godot_recipes/4.x/ai/path_follow/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/ai/path_follow/index.html</guid><description>&lt;div class="box notices cstyle tip"&gt;
&lt;div class="box-label"&gt;&lt;i class="fa-fw fas fa-lightbulb"&gt;&lt;/i&gt; Tip&lt;/div&gt;
&lt;div class="box-content"&gt;
&lt;p&gt;This article is being updated from Godot 3 to Godot 4.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;p&gt;You want a character to follow a pre-defined path, such as a guard patrolling or a car following the road.&lt;/p&gt;
&lt;h2 id="solution"&gt;Solution&lt;/h2&gt;
&lt;p&gt;There are many ways to approach this problem. In this solution, we&amp;rsquo;ll use Godot&amp;rsquo;s &lt;i class="gd-Path2D"&gt;&lt;/i&gt;&lt;code&gt;Path2D&lt;/code&gt; node (or &lt;i class="gd-Path3D"&gt;&lt;/i&gt;&lt;code&gt;Path&lt;/code&gt; for 3D) as a convenient way to draw paths in the editor.&lt;/p&gt;
&lt;p&gt;You can add the &lt;i class="gd-Path2D"&gt;&lt;/i&gt;&lt;code&gt;Path2D&lt;/code&gt; as a child of your main scene, your map, or another location that makes sense. Don&amp;rsquo;t make it a child of the patrolling entity, though - or the path will move along with the player!&lt;/p&gt;</description></item><item><title>Homing missile</title><link>https://kamera25.github.io/godot_recipes/4.x/ai/homing_missile/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/ai/homing_missile/index.html</guid><description>&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;p&gt;You need a &amp;ldquo;homing missile&amp;rdquo; - a projectile that will seek a moving target.&lt;/p&gt;
&lt;h2 id="solution"&gt;Solution&lt;/h2&gt;
&lt;p&gt;For this example, we&amp;rsquo;ll use an &lt;i class="gd-Area2D"&gt;&lt;/i&gt;&lt;code&gt;Area2D&lt;/code&gt; node for the projectile. Areas are typically good choices for bullets because we need to detect when they contact something. If you also need a bullet that bounces/ricochets, one of the &lt;code&gt;PhysicsBody&lt;/code&gt; type node might be a better choice.&lt;/p&gt;
&lt;p&gt;The node setup and behavior of the missile is the same you would use for a &amp;ldquo;dumb&amp;rdquo; bullet. If you&amp;rsquo;re creating many bullet types, you can use inheritance to base all your projectiles on the same core setup.&lt;/p&gt;</description></item><item><title>Context-based steering</title><link>https://kamera25.github.io/godot_recipes/4.x/ai/context_map/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/ai/context_map/index.html</guid><description>&lt;div class="box notices cstyle tip"&gt;
&lt;div class="box-label"&gt;&lt;i class="fa-fw fas fa-lightbulb"&gt;&lt;/i&gt; Tip&lt;/div&gt;
&lt;div class="box-content"&gt;
&lt;p&gt;This article is being updated from Godot 3 to Godot 4.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;p&gt;You need an AI-controlled object in your game that can follow a path, avoid obstacles, and make other decisions about how to move around the world.&lt;/p&gt;
&lt;h2 id="solution"&gt;Solution&lt;/h2&gt;
&lt;p&gt;&amp;ldquo;Steering behavior&amp;rdquo; is the blanket term for a variety of algorithms that you can use to solve this problem. Which one you choose will depend on your game, the type of world the object lives in, and what type of &amp;ldquo;intelligence&amp;rdquo; you want it to have.&lt;/p&gt;</description></item><item><title>Pet Following</title><link>https://kamera25.github.io/godot_recipes/4.x/ai/pet_following/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/ai/pet_following/index.html</guid><description>&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;p&gt;You need to have a game entity such as a pet or minion, follow a character.&lt;/p&gt;
&lt;p&gt;&lt;video controls src='https://kamera25.github.io/godot_recipes/4.x/img/pet_follow.webm'&gt;&lt;/video&gt;&lt;/p&gt;
&lt;h2 id="solution"&gt;Solution&lt;/h2&gt;
&lt;p&gt;We start by adding a &lt;i class="gd-Marker2D"&gt;&lt;/i&gt;&lt;code&gt;Marker2D&lt;/code&gt; to the character. This will represent the place where the pet wants to &amp;ldquo;hang out&amp;rdquo; near the character.&lt;/p&gt;
&lt;p&gt;
&lt;a href="#image-72ae504d6112d69d5abc2e414cdcbebd" class="lightbox-link"&gt;
&lt;img src="https://kamera25.github.io/godot_recipes/4.x/img/pet_follow_01.png" alt="alt" style="height: auto; width: auto;" loading="lazy"&gt;
&lt;/a&gt;
&lt;a href="javascript:history.back();" class="lightbox" id="image-72ae504d6112d69d5abc2e414cdcbebd"&gt;
&lt;img src="https://kamera25.github.io/godot_recipes/4.x/img/pet_follow_01.png" alt="alt" class="lightbox-image" loading="lazy"&gt;
&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In this example, we&amp;rsquo;ve made it a child of the &lt;i class="gd-Sprite2D"&gt;&lt;/i&gt;&lt;code&gt;Sprite2D&lt;/code&gt;, because the character&amp;rsquo;s code uses &lt;code&gt;$Sprite2D.scale.x = -1&lt;/code&gt; to flip the horizontal direction when the character moves left. Since the marker is a child of the sprite, it will flip too.&lt;/p&gt;</description></item></channel></rss>