<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>2D on Godot 4 レシピ</title><link>https://kamera25.github.io/godot_recipes/4.x/2d/index.html</link><description>Recent content in 2D on Godot 4 レシピ</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="https://kamera25.github.io/godot_recipes/4.x/2d/index.xml" rel="self" type="application/rss+xml"/><item><title>Entering/Exiting the screen</title><link>https://kamera25.github.io/godot_recipes/4.x/2d/enter_exit_screen/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/2d/enter_exit_screen/index.html</guid><description>&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;p&gt;You want to detect when an object enters or exits the screen.&lt;/p&gt;
&lt;h2 id="solution"&gt;Solution&lt;/h2&gt;
&lt;p&gt;The engine provides a node for this: &lt;i class="gd-VisibleOnScreenNotifier2D"&gt;&lt;/i&gt;&lt;code&gt;VisibleOnScreenNotifier2D&lt;/code&gt;. Attach this node to your object, and you&amp;rsquo;ll be able to use its &lt;code&gt;screen_entered&lt;/code&gt; and &lt;code&gt;screen_exited&lt;/code&gt; signals.
*&lt;/p&gt;
&lt;h4 id="example-1"&gt;Example 1&lt;/h4&gt;
&lt;p&gt;Consider a projectile that travels in a straight line after it&amp;rsquo;s fired. If we continue firing, eventually we&amp;rsquo;ll have a large number of objects for the engine to track, event though they&amp;rsquo;re offscreen, which can cause lag.&lt;/p&gt;</description></item><item><title>Platform character</title><link>https://kamera25.github.io/godot_recipes/4.x/2d/platform_character/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/2d/platform_character/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 to make a 2D platform-style character.&lt;/p&gt;
&lt;h2 id="solution"&gt;Solution&lt;/h2&gt;
&lt;p&gt;New developers are often surprised at how complex a platform character can be to program. Godot provides some built-in tools to assist, but there are as many solutions as there are games. In this tutorial, we won&amp;rsquo;t be going in-depth with features like double-jumps, crouching, wall-jumps, or animation. Here we&amp;rsquo;ll discuss the fundamentals of platformer movement. See the rest of the recipes for other solutions.&lt;/p&gt;</description></item><item><title>Screen wrap</title><link>https://kamera25.github.io/godot_recipes/4.x/2d/screen_wrap/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/2d/screen_wrap/index.html</guid><description>&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;p&gt;You want to allow the player to &amp;ldquo;wrap around&amp;rdquo; the screen, teleporting from one side of the screen to the other. This is a common feature, especially in old-school 2D games (think Pac-man).&lt;/p&gt;
&lt;h2 id="solution"&gt;Solution&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Get your screen (viewport) size&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-gdscript" data-lang="gdscript"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#d08770"&gt;@onready&lt;/span&gt; &lt;span style="color:#81a1c1;font-weight:bold"&gt;var&lt;/span&gt; screen_size &lt;span style="color:#81a1c1"&gt;=&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;get_viewport_rect&lt;/span&gt;&lt;span style="color:#eceff4"&gt;()&lt;/span&gt;&lt;span style="color:#81a1c1"&gt;.&lt;/span&gt;size
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;get_viewport_rect()&lt;/code&gt; is available to any &lt;code&gt;CanvasItem&lt;/code&gt; derived node.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Compare your player&amp;rsquo;s position&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-gdscript" data-lang="gdscript"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#81a1c1;font-weight:bold"&gt;if&lt;/span&gt; position&lt;span style="color:#81a1c1"&gt;.&lt;/span&gt;x &lt;span style="color:#81a1c1"&gt;&amp;gt;&lt;/span&gt; screen_size&lt;span style="color:#81a1c1"&gt;.&lt;/span&gt;x&lt;span style="color:#eceff4"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; position&lt;span style="color:#81a1c1"&gt;.&lt;/span&gt;x &lt;span style="color:#81a1c1"&gt;=&lt;/span&gt; &lt;span style="color:#b48ead"&gt;0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#81a1c1;font-weight:bold"&gt;if&lt;/span&gt; position&lt;span style="color:#81a1c1"&gt;.&lt;/span&gt;x &lt;span style="color:#81a1c1"&gt;&amp;lt;&lt;/span&gt; &lt;span style="color:#b48ead"&gt;0&lt;/span&gt;&lt;span style="color:#eceff4"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; position&lt;span style="color:#81a1c1"&gt;.&lt;/span&gt;x &lt;span style="color:#81a1c1"&gt;=&lt;/span&gt; screen_size&lt;span style="color:#81a1c1"&gt;.&lt;/span&gt;x
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#81a1c1;font-weight:bold"&gt;if&lt;/span&gt; position&lt;span style="color:#81a1c1"&gt;.&lt;/span&gt;y &lt;span style="color:#81a1c1"&gt;&amp;gt;&lt;/span&gt; screen_size&lt;span style="color:#81a1c1"&gt;.&lt;/span&gt;y&lt;span style="color:#eceff4"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; position&lt;span style="color:#81a1c1"&gt;.&lt;/span&gt;y &lt;span style="color:#81a1c1"&gt;=&lt;/span&gt; &lt;span style="color:#b48ead"&gt;0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#81a1c1;font-weight:bold"&gt;if&lt;/span&gt; position&lt;span style="color:#81a1c1"&gt;.&lt;/span&gt;y &lt;span style="color:#81a1c1"&gt;&amp;lt;&lt;/span&gt; &lt;span style="color:#b48ead"&gt;0&lt;/span&gt;&lt;span style="color:#eceff4"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; position&lt;span style="color:#81a1c1"&gt;.&lt;/span&gt;y &lt;span style="color:#81a1c1"&gt;=&lt;/span&gt; screen_size&lt;span style="color:#81a1c1"&gt;.&lt;/span&gt;y
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Note that this is using the node&amp;rsquo;s &lt;code&gt;position&lt;/code&gt;, which is usually the center of your sprite and/or body.&lt;/p&gt;</description></item><item><title>Splitscreen multiplayer</title><link>https://kamera25.github.io/godot_recipes/4.x/2d/splitscreen_demo/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/2d/splitscreen_demo/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="introduction"&gt;Introduction&lt;/h2&gt;
&lt;p&gt;In this demo, we&amp;rsquo;ll consider a local multiplayer game - a topdown-style maze game with
two players (one using arrow keys and the other using WASD controls). This is
not a problem if our game world all fits on one screen, but if the map is large,
we&amp;rsquo;ll want to have a &amp;ldquo;split screen&amp;rdquo; view tracking the two players separately.&lt;/p&gt;</description></item><item><title>TileMap: detecting tiles</title><link>https://kamera25.github.io/godot_recipes/4.x/2d/tilemap_collision/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/2d/tilemap_collision/index.html</guid><description>&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;p&gt;You have a &lt;i class="gd-CharacterBody2D"&gt;&lt;/i&gt;&lt;code&gt;CharacterBody2D&lt;/code&gt; character colliding with a &lt;i class="gd-TileMap"&gt;&lt;/i&gt;&lt;code&gt;TileMap&lt;/code&gt;, and you want to know which tile it collided with.&lt;/p&gt;
&lt;h2 id="solution"&gt;Solution&lt;/h2&gt;
&lt;p&gt;When a &lt;i class="gd-CharacterBody2D"&gt;&lt;/i&gt;&lt;code&gt;CharacterBody2D&lt;/code&gt; collides, the collision data is returned in a &lt;code&gt;KinematicCollision2D&lt;/code&gt; object. The &lt;i class="gd-TileMap"&gt;&lt;/i&gt;&lt;code&gt;TileMap&lt;/code&gt; acts as a single collider, so if you reference the &lt;code&gt;collider&lt;/code&gt; property, it will be the &lt;i class="gd-TileMap"&gt;&lt;/i&gt;&lt;code&gt;TileMap&lt;/code&gt; node.&lt;/p&gt;
&lt;p&gt;You then need to find out which tile in the &lt;i class="gd-TileMap"&gt;&lt;/i&gt;&lt;code&gt;TileMap&lt;/code&gt; is at the collision location.&lt;/p&gt;
&lt;p&gt;Assume you&amp;rsquo;ve obtained a &lt;code&gt;KinematicCollision2D&lt;/code&gt; object stored in the variable &lt;code&gt;collision&lt;/code&gt;:&lt;/p&gt;</description></item><item><title>Top-down movement</title><link>https://kamera25.github.io/godot_recipes/4.x/2d/topdown_movement/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/2d/topdown_movement/index.html</guid><description>&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;p&gt;You&amp;rsquo;re making a 2D top-down game, and you want to control a character&amp;rsquo;s movement.&lt;/p&gt;
&lt;h2 id="solution"&gt;Solution&lt;/h2&gt;
&lt;p&gt;For this solution, we&amp;rsquo;ll assume you have the following input actions defined:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Action Name&lt;/th&gt;
&lt;th&gt;Key(s)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;quot;up&amp;quot;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;W,↑&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;quot;down&amp;quot;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;S,↓&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;quot;right&amp;quot;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;D,→&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;quot;left&amp;quot;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;A,←&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;quot;click&amp;quot;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Mouse button 1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;We will also assume you&amp;rsquo;re using a &lt;i class="gd-CharacterBody2D"&gt;&lt;/i&gt;&lt;code&gt;CharacterBody2D&lt;/code&gt; node.&lt;/p&gt;
&lt;p&gt;We can solve this problem in many ways, depending on what type of behavior you&amp;rsquo;re looking for.&lt;/p&gt;
&lt;h3 id="option-1-8-way-movement"&gt;Option 1: 8-way movement&lt;/h3&gt;
&lt;p&gt;In this scenario, the player uses the four directional keys to move (including diagonals).&lt;/p&gt;</description></item><item><title>Grid-based movement</title><link>https://kamera25.github.io/godot_recipes/4.x/2d/grid_movement/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/2d/grid_movement/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 a 2D character that moves in a grid pattern.&lt;/p&gt;
&lt;h2 id="solution"&gt;Solution&lt;/h2&gt;
&lt;p&gt;Grid- or tile-based movement means the character&amp;rsquo;s position is restricted. They can only stand on a particular tile - never between two tiles.&lt;/p&gt;
&lt;h3 id="character-setup"&gt;Character setup&lt;/h3&gt;
&lt;p&gt;Here are the nodes we&amp;rsquo;ll use for the player:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;i class="gd-Area2D"&gt;&lt;/i&gt;&lt;code&gt;Area2D&lt;/code&gt; (&amp;ldquo;Player&amp;rdquo;): Using an &lt;i class="gd-Area2D"&gt;&lt;/i&gt;&lt;code&gt;Area2D&lt;/code&gt; means we can detect overlap (for picking up objects or colliding with enemies).
&lt;ul&gt;
&lt;li&gt;&lt;i class="gd-Sprite2D"&gt;&lt;/i&gt;&lt;code&gt;Sprite2D&lt;/code&gt;: You can use a sprite sheet here (we&amp;rsquo;ll set up the animation below).&lt;/li&gt;
&lt;li&gt;&lt;i class="gd-CollisionShape2D"&gt;&lt;/i&gt;&lt;code&gt;CollisionShape2D&lt;/code&gt;: Don&amp;rsquo;t make the hitbox too big. Since the player will be standing on the center of a tile, overlaps will be from the center.&lt;/li&gt;
&lt;li&gt;&lt;i class="gd-RayCast2D"&gt;&lt;/i&gt;&lt;code&gt;RayCast2D&lt;/code&gt;: For checking if movement is possible in the given direction.&lt;/li&gt;
&lt;li&gt;&lt;i class="gd-AnimationPlayer"&gt;&lt;/i&gt;&lt;code&gt;AnimationPlayer&lt;/code&gt;: For playing the character&amp;rsquo;s walk animation(s).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Add some input actions to the Input Map. We&amp;rsquo;ll use &amp;ldquo;up&amp;rdquo;, &amp;ldquo;down&amp;rdquo;, &amp;ldquo;left&amp;rdquo;, and &amp;ldquo;right&amp;rdquo; for this example.&lt;/p&gt;</description></item><item><title>Shooting projectiles</title><link>https://kamera25.github.io/godot_recipes/4.x/2d/2d_shooting/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/2d/2d_shooting/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 to shoot projectiles from your player/mob/etc..&lt;/p&gt;
&lt;h2 id="solution"&gt;Solution&lt;/h2&gt;
&lt;h3 id="setting-up-the-bullet"&gt;Setting up the bullet&lt;/h3&gt;
&lt;p&gt;First, we&amp;rsquo;ll set up a &amp;ldquo;bullet&amp;rdquo; object that we can instance. Here are the nodes we&amp;rsquo;ll use:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;&lt;i class="gd-Area2D"&gt;&lt;/i&gt; Area2D: Bullet
&lt;i class="gd-Sprite2D"&gt;&lt;/i&gt; Sprite2D
&lt;i class="gd-CollisionShape2D"&gt;&lt;/i&gt; CollisionShape2D
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For the &lt;i class="gd-Sprite2D"&gt;&lt;/i&gt;&lt;code&gt;Sprite2D&lt;/code&gt;&amp;rsquo;s texture, you can use any image you like. Here&amp;rsquo;s an example one:&lt;/p&gt;
&lt;p&gt;
&lt;a href="#image-e89482ac42859ecdc79b97525aac87c4" class="lightbox-link"&gt;
&lt;img src="https://kamera25.github.io/godot_recipes/4.x/img/laserRed01.png" alt="alt" style="height: auto; width: auto;" loading="lazy"&gt;
&lt;/a&gt;
&lt;a href="javascript:history.back();" class="lightbox" id="image-e89482ac42859ecdc79b97525aac87c4"&gt;
&lt;img src="https://kamera25.github.io/godot_recipes/4.x/img/laserRed01.png" alt="alt" class="lightbox-image" loading="lazy"&gt;
&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Set up the nodes and configure the sprite and collision shape. If your texture is oriented pointing up, like the one above, make sure to rotate the &lt;i class="gd-Sprite2D"&gt;&lt;/i&gt;&lt;code&gt;Sprite&lt;/code&gt; node by &lt;code&gt;90°&lt;/code&gt; so that it&amp;rsquo;s pointing to the right, ensuring it matches the parent’s “forward” direction.&lt;/p&gt;</description></item><item><title>Car steering</title><link>https://kamera25.github.io/godot_recipes/4.x/2d/car_steering/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/2d/car_steering/index.html</guid><description>&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;p&gt;You need to create a 2D top-down car controller.&lt;/p&gt;
&lt;h2 id="solution"&gt;Solution&lt;/h2&gt;
&lt;p&gt;When approaching this problem, beginners often wind up creating something that handles nothing like a real car. Some common mistakes you&amp;rsquo;ll find in amateur car games:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A car doesn&amp;rsquo;t rotate around its center. Put another way, a car&amp;rsquo;s rear wheels don&amp;rsquo;t slide side-to-side. (Unless it&amp;rsquo;s drifting, but we&amp;rsquo;ll talk about that later.)&lt;/li&gt;
&lt;li&gt;A car can &lt;em&gt;only&lt;/em&gt; turn when it&amp;rsquo;s moving - it can&amp;rsquo;t spin in place.&lt;/li&gt;
&lt;li&gt;A car isn&amp;rsquo;t a train; it&amp;rsquo;s not on rails. Turning at high speeds should involve some sliding (drifting).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There are many approaches to 2D car physics, mainly depending on how &amp;ldquo;realistic&amp;rdquo; you want to be. For this solution, we&amp;rsquo;re going for an &amp;ldquo;arcade&amp;rdquo; level of realism, meaning we&amp;rsquo;ll prioritize action over realism.&lt;/p&gt;</description></item><item><title>8-Directional Movement/Animation</title><link>https://kamera25.github.io/godot_recipes/4.x/2d/8_direction/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/2d/8_direction/index.html</guid><description>&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;p&gt;You need a 2D character that has 8-directional movement, including animation.&lt;/p&gt;
&lt;h2 id="solution"&gt;Solution&lt;/h2&gt;
&lt;p&gt;For our example, we&amp;rsquo;ll use the &lt;a href="https://remos.itch.io/mini-crusader" target="_blank"&gt;Isometric Mini-Crusader&lt;/a&gt;, which contains 8-directional animations for idle, run, attack, and several other states.&lt;/p&gt;
&lt;p&gt;
&lt;a href="#image-d094fc9e2399234daa7e7d870b346c67" class="lightbox-link"&gt;
&lt;img src="https://kamera25.github.io/godot_recipes/4.x/img/8_direction_01.gif" alt="alt" style="height: auto; width: auto;" loading="lazy"&gt;
&lt;/a&gt;
&lt;a href="javascript:history.back();" class="lightbox" id="image-d094fc9e2399234daa7e7d870b346c67"&gt;
&lt;img src="https://kamera25.github.io/godot_recipes/4.x/img/8_direction_01.gif" alt="alt" class="lightbox-image" loading="lazy"&gt;
&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The animations are organized in folders, with a separate image for each frame. We&amp;rsquo;ll use an &lt;i class="gd-AnimatedSprite2D"&gt;&lt;/i&gt;&lt;code&gt;AnimatedSprite2D&lt;/code&gt; and we&amp;rsquo;ll name each animation based on its direction. For example, &lt;code&gt;idle0&lt;/code&gt; pointing to the right and going clockwise to &lt;code&gt;idle7&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>TileMap: using autotile</title><link>https://kamera25.github.io/godot_recipes/4.x/2d/autotile_intro/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/2d/autotile_intro/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 are using a &lt;i class="gd-TileMap"&gt;&lt;/i&gt; TileMap, and want to use autotiling to more quickly draw your levels.&lt;/p&gt;
&lt;h2 id="solution"&gt;Solution&lt;/h2&gt;
&lt;p&gt;For this demo, we&amp;rsquo;ll be using the following tileset:&lt;/p&gt;
&lt;p&gt;
&lt;a href="#image-ec99cd73e374a7be421d4ffd0934a3e9" class="lightbox-link"&gt;
&lt;img src="https://kamera25.github.io/godot_recipes/4.x/godot_recipes/3.x/img/autotile_tileset.png" alt="alt" style="height: auto; width: auto;" loading="lazy"&gt;
&lt;/a&gt;
&lt;a href="javascript:history.back();" class="lightbox" id="image-ec99cd73e374a7be421d4ffd0934a3e9"&gt;
&lt;img src="https://kamera25.github.io/godot_recipes/4.x/godot_recipes/3.x/img/autotile_tileset.png" alt="alt" class="lightbox-image" loading="lazy"&gt;
&lt;/a&gt;&lt;/p&gt;
&lt;div class="box notices cstyle note"&gt;
&lt;div class="box-label"&gt;&lt;i class="fa-fw fas fa-exclamation-circle"&gt;&lt;/i&gt; Note&lt;/div&gt;
&lt;div class="box-content"&gt;
&lt;p&gt;These tiles are from Kenney&amp;rsquo;s &amp;ldquo;Topdown Shooter&amp;rdquo; art pack, which you can find here:&lt;a href="https://kenney.nl/assets/topdown-shooter" target="_blank"&gt;https://kenney.nl/assets/topdown-shooter&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Creating a map from these tiles, if you were adding them one-by-one, would be a tedious process. You would be constantly changing between tiles to line up corners, intersections, and endpoints.&lt;/p&gt;</description></item><item><title>Using Y-Sort</title><link>https://kamera25.github.io/godot_recipes/4.x/2d/using_ysort/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/2d/using_ysort/index.html</guid><description>&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;p&gt;Many 2D games use a &amp;ldquo;3/4 view&amp;rdquo; perspective, giving the impression that the camera is looking at the world at an angle. To make this work, objects that are &amp;ldquo;farther&amp;rdquo; away need to be rendered behind &amp;ldquo;nearer&amp;rdquo; objects. In practice, that means we want to &amp;ldquo;y-sort&amp;rdquo; - making the drawing order tied to the object&amp;rsquo;s &lt;code&gt;y&lt;/code&gt; coordinate. The higher on the screen, the farther away and therefore lower the render order.&lt;/p&gt;</description></item><item><title>Coyote Time</title><link>https://kamera25.github.io/godot_recipes/4.x/2d/coyote_time/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/2d/coyote_time/index.html</guid><description>&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;p&gt;Your platformer jumping feels &amp;ldquo;off&amp;rdquo;. Players don&amp;rsquo;t have good control and sometimes they &amp;ldquo;miss&amp;rdquo; jumping off the edge of platforms.&lt;/p&gt;
&lt;h2 id="solution"&gt;Solution&lt;/h2&gt;
&lt;p&gt;The answer to this problem is to use a technique called &amp;ldquo;coyote time&amp;rdquo;. This gives the player a greater feeling of control and a little &amp;ldquo;wiggle room&amp;rdquo; around the process of jumping from the edges of platforms.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Coyote time&amp;rdquo; works like this:&lt;/p&gt;
&lt;p&gt;If the player walks off the edge of a platform, for a few frames afterward, we still allow them to jump as if they were still on the ground.&lt;/p&gt;</description></item><item><title>Moving Platforms</title><link>https://kamera25.github.io/godot_recipes/4.x/2d/moving_platforms/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/2d/moving_platforms/index.html</guid><description>&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;p&gt;You need moving platforms in your 2D platformer.&lt;/p&gt;
&lt;h2 id="solution"&gt;Solution&lt;/h2&gt;
&lt;p&gt;There are several ways to approach this problem. In this recipe, we&amp;rsquo;ll use &lt;i class="gd-AnimatableBody2D"&gt;&lt;/i&gt;&lt;code&gt;AnimatableBody2D&lt;/code&gt;s for our platform and move it with a &lt;i class="gd-Tween"&gt;&lt;/i&gt;&lt;code&gt;Tween&lt;/code&gt;. This allows for a variety of movement styles while minimizing the amount of code we need to write.&lt;/p&gt;
&lt;div class="box notices cstyle info"&gt;
&lt;div class="box-label"&gt;&lt;i class="fa-fw fas fa-info-circle"&gt;&lt;/i&gt; Info&lt;/div&gt;
&lt;div class="box-content"&gt;
&lt;p&gt;You can also implement this moving platform technique using an &lt;i class="gd-AnimationPlayer"&gt;&lt;/i&gt;&lt;code&gt;AnimationPlayer&lt;/code&gt; rather than a tween. Much of the setup will be the same, but rather than tween code, you&amp;rsquo;ll animate the body&amp;rsquo;s &lt;code&gt;position&lt;/code&gt; property.&lt;/p&gt;</description></item><item><title>Pathfinding on a 2D Grid</title><link>https://kamera25.github.io/godot_recipes/4.x/2d/grid_pathfinding/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/2d/grid_pathfinding/index.html</guid><description>&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;p&gt;You have a grid-based environment and you&amp;rsquo;d like to set up pathfinding to allow navigation.&lt;/p&gt;
&lt;h2 id="solution"&gt;Solution&lt;/h2&gt;
&lt;p&gt;Godot provides a number of methods for pathfinding. For this recipe, we&amp;rsquo;ll consider the &lt;code&gt;A*&lt;/code&gt; algorithm.&lt;/p&gt;
&lt;div class="box notices cstyle info"&gt;
&lt;div class="box-label"&gt;&lt;i class="fa-fw fas fa-info-circle"&gt;&lt;/i&gt; About A*&lt;/div&gt;
&lt;div class="box-content"&gt;
&lt;p&gt;A* is a widely-used algorithm for finding the shortest path between two points. It can be used in any graph-based data structure, not just a grid.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;AStarGrid2D&lt;/code&gt; is a specialized version of Godot&amp;rsquo;s more generic &lt;code&gt;AStar2D&lt;/code&gt; class. Because it&amp;rsquo;s specialized for using with a grid, it&amp;rsquo;s quicker and easier to set up because you don&amp;rsquo;t have to manually add all the individual grid cells and their connections.&lt;/p&gt;</description></item><item><title>TileMap: animated tiles</title><link>https://kamera25.github.io/godot_recipes/4.x/2d/tilemap_animation/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/2d/tilemap_animation/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&amp;rsquo;d like to use animated tiles in your TileMap.&lt;/p&gt;
&lt;h2 id="solution"&gt;Solution&lt;/h2&gt;
&lt;p&gt;The most straightforward way to approach this problem is to use the &lt;code&gt;AnimatedTexture&lt;/code&gt; resource.&lt;/p&gt;
&lt;h3 id="creating-an-animatedtexture"&gt;Creating an AnimatedTexture&lt;/h3&gt;
&lt;p&gt;For this example, we&amp;rsquo;ll use the following water tiles:&lt;/p&gt;
&lt;p&gt;
&lt;a href="#image-f29fc0b84a96498cb9babf6fbed9ea9b" class="lightbox-link"&gt;
&lt;img src="https://kamera25.github.io/godot_recipes/4.x/godot_recipes/3.x/img/anim_tiles.png" alt="alt" style="height: auto; width: auto;" loading="lazy"&gt;
&lt;/a&gt;
&lt;a href="javascript:history.back();" class="lightbox" id="image-f29fc0b84a96498cb9babf6fbed9ea9b"&gt;
&lt;img src="https://kamera25.github.io/godot_recipes/4.x/godot_recipes/3.x/img/anim_tiles.png" alt="alt" class="lightbox-image" loading="lazy"&gt;
&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Download these images: &lt;a href="https://kamera25.github.io/godot_recipes/4.x/godot_recipes/3.x/files/water_tiles.zip"&gt;water.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Unzip the images into your project folder.
In the Inspector, click the &amp;ldquo;Create a new resource&amp;rdquo; button:&lt;/p&gt;</description></item><item><title>Multitarget Camera</title><link>https://kamera25.github.io/godot_recipes/4.x/2d/multi_target_camera/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/2d/multi_target_camera/index.html</guid><description>&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;p&gt;You need a dynamic camera that moves and zooms to keep multiple objects on screen at the same time.&lt;/p&gt;
&lt;p&gt;An example might be in a 2 player game, keeping both players on-screen as they move farther and closer together, like so:&lt;/p&gt;
&lt;p&gt;
&lt;a href="#image-bb66a8979fddbfa629398d088b2dcc79" class="lightbox-link"&gt;
&lt;img src="https://kamera25.github.io/godot_recipes/4.x/img/multi_cam_01.gif" alt="alt" style="height: auto; width: auto;" loading="lazy"&gt;
&lt;/a&gt;
&lt;a href="javascript:history.back();" class="lightbox" id="image-bb66a8979fddbfa629398d088b2dcc79"&gt;
&lt;img src="https://kamera25.github.io/godot_recipes/4.x/img/multi_cam_01.gif" alt="alt" class="lightbox-image" loading="lazy"&gt;
&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="solution"&gt;Solution&lt;/h2&gt;
&lt;p&gt;In a single-player game, you&amp;rsquo;re probably used to attaching the camera to the player, so that it automatically follows them. We can&amp;rsquo;t really do this here because we have 2 (or more) players or other game objects that we want to keep on the screen at all times.&lt;/p&gt;</description></item><item><title>Ballistic bullet</title><link>https://kamera25.github.io/godot_recipes/4.x/2d/ballistic_bullet/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/2d/ballistic_bullet/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 2D bullet that travels in an arc, or ballistic curve.&lt;/p&gt;
&lt;h2 id="solution"&gt;Solution&lt;/h2&gt;
&lt;p&gt;One approach to this problem would be to use a &lt;i class="gd-RigidBody2D"&gt;&lt;/i&gt;&lt;code&gt;RigidBody2D&lt;/code&gt; - with its built-in physics, gravity would automatically pull it back to earth after firing it.&lt;/p&gt;
&lt;p&gt;However, as mentioned in the &lt;a href="https://kamera25.github.io/godot_recipes/4.x/godot_recipes/3.x/2d/2d_shooting/"&gt;2D shooting recipe&lt;/a&gt;, &lt;i class="gd-Area2D"&gt;&lt;/i&gt;&lt;code&gt;Area2D&lt;/code&gt; is a great choice for simple bullets and other projectiles - when you don&amp;rsquo;t need collisions, bouncing, or other physics reactions. Ballistic motion is easy enough to calculate that we won&amp;rsquo;t need the help of the physics engine.&lt;/p&gt;</description></item><item><title>Line2D Collision</title><link>https://kamera25.github.io/godot_recipes/4.x/2d/line_collision/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/2d/line_collision/index.html</guid><description>&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;p&gt;You want to have collisions with a &lt;i class="gd-Line2D"&gt;&lt;/i&gt;&lt;code&gt;Line2D&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="solution"&gt;Solution&lt;/h2&gt;
&lt;h3 id="node-setup"&gt;Node setup&lt;/h3&gt;
&lt;p&gt;Add the following nodes to your scene, and draw your line as desired:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;&lt;i class="gd-Line2D"&gt;&lt;/i&gt; Line2D
&lt;i class="gd-StaticBody2D"&gt;&lt;/i&gt; StaticBody2D
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Don&amp;rsquo;t add a collision shape to the body yet!&lt;/p&gt;
&lt;div class="box notices cstyle note"&gt;
&lt;div class="box-label"&gt;&lt;i class="fa-fw fas fa-exclamation-circle"&gt;&lt;/i&gt; Note&lt;/div&gt;
&lt;div class="box-content"&gt;
&lt;p&gt;You can use an &lt;i class="gd-Area2D"&gt;&lt;/i&gt;&lt;code&gt;Area2D&lt;/code&gt; instead if you want to detect overlap with the line rather than collision.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Next, we need to add collision shapes to the body. We have two options:&lt;/p&gt;</description></item><item><title>Touchscreen Camera</title><link>https://kamera25.github.io/godot_recipes/4.x/2d/touchscreen_camera/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/2d/touchscreen_camera/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 a touch-controlled 2D camera for your mobile game.&lt;/p&gt;
&lt;h2 id="solution"&gt;Solution&lt;/h2&gt;
&lt;p&gt;In this recipe, we&amp;rsquo;ll create a generic 2D camera with multiple touch controls:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Drag to pan&lt;/li&gt;
&lt;li&gt;Pinch to zoom&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="setup"&gt;Setup&lt;/h3&gt;
&lt;p&gt;Our camera will extend the built-in node, so add a &lt;i class="gd-Camera2D"&gt;&lt;/i&gt;&lt;code&gt;Camera2D&lt;/code&gt; to a new scene and name it &amp;ldquo;TouchCamera&amp;rdquo;. Save and attach a script.&lt;/p&gt;</description></item><item><title>Draw trajectory</title><link>https://kamera25.github.io/godot_recipes/4.x/2d/2d_draw_trajectory/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/2d/2d_draw_trajectory/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 to draw the trajectory of a ballistic shot, like from a tank.&lt;/p&gt;
&lt;h2 id="solution"&gt;Solution&lt;/h2&gt;
&lt;h3 id="setup"&gt;Setup&lt;/h3&gt;
&lt;p&gt;For this example, we&amp;rsquo;re using the &amp;ldquo;Ballistic Bullet&amp;rdquo; from this recipe:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://kamera25.github.io/godot_recipes/4.x/godot_recipes/3.x/2d/ballistic_bullet/"&gt;Ballistic bullet&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;and a tank set up like so, with a &lt;i class="gd-Marker2D"&gt;&lt;/i&gt;&lt;code&gt;Marker2D&lt;/code&gt; designating the &amp;ldquo;muzzle&amp;rdquo; where the bullet will be spawned:&lt;/p&gt;
&lt;p&gt;
&lt;a href="#image-dbf103ab4d2c517dd39bb0db0949268c" class="lightbox-link"&gt;
&lt;img src="https://kamera25.github.io/godot_recipes/4.x/godot_recipes/3.x/img/tank_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-dbf103ab4d2c517dd39bb0db0949268c"&gt;
&lt;img src="https://kamera25.github.io/godot_recipes/4.x/godot_recipes/3.x/img/tank_01.png" alt="alt" class="lightbox-image" loading="lazy"&gt;
&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In the tank&amp;rsquo;s script, we instance the bullet like so:&lt;/p&gt;</description></item></channel></rss>