summaryrefslogtreecommitdiff
path: root/live/blog/g
diff options
context:
space:
mode:
authorDavid Luevano Alvarado <david@luevano.xyz>2023-08-29 04:17:09 -0600
committerDavid Luevano Alvarado <david@luevano.xyz>2023-08-29 04:17:09 -0600
commite6fb8b69c85894994d649b4c7c59a6a1fa606c34 (patch)
treeda723dabaac5128634eddeecf9f982f899f604cf /live/blog/g
parent06184c13af639917e1af5a1bc298b0022c1398ea (diff)
add godot layer notes
Diffstat (limited to 'live/blog/g')
-rw-r--r--live/blog/g/flappybird_godot_devlog_2.html10
-rw-r--r--live/blog/g/godot_layers_and_masks_notes.html164
2 files changed, 172 insertions, 2 deletions
diff --git a/live/blog/g/flappybird_godot_devlog_2.html b/live/blog/g/flappybird_godot_devlog_2.html
index b7a5047..d4f764b 100644
--- a/live/blog/g/flappybird_godot_devlog_2.html
+++ b/live/blog/g/flappybird_godot_devlog_2.html
@@ -116,7 +116,7 @@
</ul>
</div>
<h2 id="porting-to-godot-4">Porting to Godot 4<a class="headerlink" href="#porting-to-godot-4" title="Permanent link">&para;</a></h2>
-<p><strong>Disclaimer:</strong> I started the port back in <em>Godot 4.0</em> something and left the project for a while, then opened the project again in <em>Godot 4.1</em>, and it didn&rsquo;t ask to convert anything so probably nowadays the conversion is better.</p>
+<p><strong>Disclaimer:</strong> I started the port back in <em>Godot 4.0</em> something and left the project for a while, then opened the project again in <em>Godot 4.1</em>, and it didn&rsquo;t ask to convert anything so probably nowadays the conversion is better. Godot&rsquo;s documentation is pretty useful, I looked at the <a href="https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_basics.html">GDScript reference</a> and <a href="https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_exports.html">GDScript exports</a> and that helped a lot.</p>
<h3 id="general-changes">General changes<a class="headerlink" href="#general-changes" title="Permanent link">&para;</a></h3>
<p>These include the first changes for fixing some of the conflicting code to at least make it run (no gameplay) as well as project settings adjustments.</p>
<ul>
@@ -278,6 +278,12 @@ AudioServer.set_bus_mute(_bus, true) # false to unmute
</ul>
<div class="page-nav">
+ <span class="next">
+ <a href="https://blog.luevano.xyz/g/godot_layers_and_masks_notes.html" alt="Next">
+ <i class="fas fa-arrow-left" alt="Arrow left"></i>
+ <span>Next</span>
+ </a>
+ </span>
<span class="index">
<a href="https://blog.luevano.xyz" alt="Index">
@@ -299,7 +305,7 @@ AudioServer.set_bus_mute(_bus, true) # false to unmute
<div class="article-info">
<p>By David Luévano</p>
<p>Created: Sun, Aug 27, 2023 @ 23:28 UTC</p>
- <p>Modified: Mon, Aug 28, 2023 @ 00:37 UTC</p>
+ <p>Modified: Tue, Aug 29, 2023 @ 10:14 UTC</p>
<div class="article-tags">
<p>Tags:
<a href="https://blog.luevano.xyz/tag/@english.html">english</a>, <a href="https://blog.luevano.xyz/tag/@gamedev.html">gamedev</a>, <a href="https://blog.luevano.xyz/tag/@gdscript.html">gdscript</a>, <a href="https://blog.luevano.xyz/tag/@godot.html">godot</a> </p>
diff --git a/live/blog/g/godot_layers_and_masks_notes.html b/live/blog/g/godot_layers_and_masks_notes.html
new file mode 100644
index 0000000..f13805e
--- /dev/null
+++ b/live/blog/g/godot_layers_and_masks_notes.html
@@ -0,0 +1,164 @@
+<!DOCTYPE html>
+<html class="theme-dark" lang="en
+"
+ prefix="og: https://ogp.me/ns#">
+ <head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <link rel="icon" href="https://static.luevano.xyz/images/icons/favicon.ico">
+<title>Godot layers and masks notes -- Luévano's Blog</title>
+ <meta name="description" content="Some notes I took regarding Godot's confusing collision layers and masks."/>
+<link rel="alternate" type="application/rss+xml" href="https://blog.luevano.xyz/rss.xml" title="Luévano's Blog RSS">
+ <!-- general style -->
+ <link rel="stylesheet" type="text/css" href="https://static.luevano.xyz/css/style.css">
+ <link rel="stylesheet" type="text/css" href="https://static.luevano.xyz/fork-awesome/css/fork-awesome.min.css">
+ <link rel="stylesheet" type="text/css" href="https://static.luevano.xyz/font-awesome/css/all.min.css">
+ <!-- theme related -->
+ <script type="text/javascript" src="https://static.luevano.xyz/scripts/theme.js"></script>
+ <link id="theme-css" rel="stylesheet" type="text/css" href="https://static.luevano.xyz/css/theme.css">
+ <!-- misc functions-->
+ <script type="text/javascript" src="https://static.luevano.xyz/scripts/return_top.js"></script>
+ <!-- extra -->
+
+
+ <!-- highlight support for code blocks -->
+<script type="text/javascript" src="https://static.luevano.xyz/hl/highlight.min.js"></script>
+<script type="text/javascript">
+ hljs.initHighlightingOnLoad();
+</script>
+<link id="code-theme-css" rel="stylesheet" type="text/css" href="https://static.luevano.xyz/hl/styles/nord.min.css">
+
+
+ <!-- Specific to GDScript -->
+ <script type="text/javascript" src="https://static.luevano.xyz/hl/languages/gdscript.min.js"></script>
+
+ <!-- og meta -->
+ <meta property="og:title" content="Godot layers and masks notes -- Luévano's Blog"/>
+ <meta property="og:type" content="article"/>
+ <meta property="og:url" content="https://blog.luevano.xyz/g/godot_layers_and_masks_notes.md"/>
+ <meta property="og:image" content="https://static.luevano.xyz/images/b/default.png"/>
+ <meta property="og:description" content="Some notes I took regarding Godot's confusing collision layers and masks."/>
+ <meta property="og:locale" content="en"/>
+ <meta property="og:site_name" content="Luévano's Blog"/>
+ </head>
+
+ <body>
+ <header>
+<nav>
+ <ul>
+ <li>
+ <a href="https://luevano.xyz/"><i class="fas fa-home" alt="Home"></i><span>Home</span></a>
+ </li>
+
+ <li>
+ <a href="https://blog.luevano.xyz/"><i class="fas fa-book-open" alt="Blog"></i><span>Blog</span></a>
+ </li>
+
+ <li>
+ <a href="https://art.luevano.xyz/"><i class="fas fa-paint-brush" alt="Art"></i><span>Art</span></a>
+ </li>
+
+ <li><i class="fab fa-git" alt="Git"></i><span>Git</span>
+ <ul>
+ <li><a href="https://git.luevano.xyz/" target="_blank"><i class="fab fa-git-alt" alt="Git-alt"></i></a></li>
+
+ <li><a href="https://github.com/luevano" target="_blank"><i class="fab fa-github" alt="Github"></i></a></li>
+
+ <li><a href="https://gitlab.com/dluevano" target="_blank"><i class="fab fa-gitlab" alt="Gitlab"></i></a></li>
+ </ul>
+ </li>
+
+ <li><i class="fas fa-box-open" alt="Stuff"></i><span>Stuff</span>
+ <ul>
+ <li><a href="https://gb.luevano.xyz/"><i class="fas fa-gamepad" alt="Gameboy"></i><span>Gameboy</span></a></li>
+ </ul>
+ </li>
+ </ul>
+</nav>
+
+<button class="theme-switcher" onclick="toggleTheme()"><i class="fas fa-moon"></i><i class="fas fa-sun"></i></button>
+
+ </header>
+
+ <main>
+ <div class="return-top">
+ <button class="return-top" onclick="returnTop()" id="returnTopButton">
+ <i class="fas fa-arrow-up" alt="Return to top"></i>
+ </button>
+ </div>
+ <h1>Godot layers and masks notes</h1>
+
+ <p>The first time I learned about Godot&rsquo;s collision layers and masks (will refer to them just as layers) I thought I understood them only to find out that they&rsquo;re a bit confusing when trying to figure out interactions between objects that are supposed to detect each other. On my last entry where I <a href="https://blog.luevano.xyz/g/flappybird_godot_devlog_2.html">ported the FlappyBird clone to <em>Godot 4.1</em></a> I stumbled upon an issue with the bird not colliding properly with the pipes and the ceiling detector not&hellip; well, detecting.</p>
+<p>At the end of the day the issue wasn&rsquo;t that the layers weren&rsquo;t properly setup but rather that the API to change the state of the collision layers changed between <em>Godot 3</em> and <em>Godot 4</em>: when calling <code>set_collision_layer_value</code> (or <code>.._mask</code>) instead of specifying the <code>bit</code> which starts at <code>0</code>, the <code>layer_number</code> is required that happens to start at <code>1</code>. This was a headache for like an hour and made me realise that I didn&rsquo;t understand layers that well or else I would&rsquo;ve picked the error almost instantly.</p>
+<p>While researching I found two really good short explainations that helped me grasp the concepts better in the same <a href="https://ask.godotengine.org/4010/whats-difference-between-collision-layers-collision-masks">post</a>, the first a bit technical (by <a href="https://ask.godotengine.org/user/Bojidar+Marinov">Bojidar Marinov</a>):</p>
+<ul>
+<li>If enemy&rsquo;s mask and object&rsquo;s mask are set to <code>0</code> (i.e. no layers), they will still collide with the player, because the player&rsquo;s mask still includes their respective layers.</li>
+<li>Overall, if the objects are <code>A</code> and <code>B</code>, the check for collision is <code>A.mask &amp; B.layers || B.mask &amp; A.layers</code>, where <code>&amp;</code> is bitwise-and, and <code>||</code> is the or operator. I.e. it takes the layers that correspond to the other object&rsquo;s mask, and checks if any of them is on in both places. It will then proceed to check it the other way around, and if any of the two tests passes, it would report the collision.</li>
+</ul>
+<p>And the second, shorter and less technical but still powerful (in the same post linking back to <a href="https://kidscancode.org/blog/2018/02/godot3_kinematic2d/">Godot 3.0: Using KinematicBody2D</a>):</p>
+<ul>
+<li><code>collision_layer</code> describes the layers that the object appears in. By default, all bodies are on layer <code>1</code>.</li>
+<li><code>collision_mask</code> describes what layers the body will scan for collisions. If an object isn’t in one of the mask layers, the body will ignore it. By default, all bodies scan layer <code>1</code>.</li>
+</ul>
+<p>While the complete answer is the first, as that is how layers work, the second can be used like a rule: 1) the <code>layer</code> is where the object lives, while 2) the <code>mask</code> is what the object will detect.</p>
+
+ <div class="page-nav">
+
+ <span class="index">
+ <a href="https://blog.luevano.xyz" alt="Index">
+ <i class="fas fa-home" alt="Home"></i>
+ <span>Index</span>
+ </a>
+ </span>
+
+ <span class="previous">
+ <a href="https://blog.luevano.xyz/g/flappybird_godot_devlog_2.html" alt="Previous">
+ <i class="fas fa-arrow-right" alt="Arrow right"></i>
+ <span>Previous</span>
+ </a>
+ </span>
+</div>
+
+
+ <hr>
+ <div class="article-info">
+ <p>By David Luévano</p>
+ <p>Created: Tue, Aug 29, 2023 @ 10:10 UTC</p>
+ <div class="article-tags">
+ <p>Tags:
+<a href="https://blog.luevano.xyz/tag/@english.html">english</a>, <a href="https://blog.luevano.xyz/tag/@gamedev.html">gamedev</a>, <a href="https://blog.luevano.xyz/tag/@gdscript.html">gdscript</a>, <a href="https://blog.luevano.xyz/tag/@godot.html">godot</a> </p>
+</div>
+
+ </div>
+ </main>
+
+ <footer>
+<span>
+ <i class="fas fa-address-card" alt="Contact"></i>
+ <a href="https://blog.luevano.xyz/contact.html">Contact</a>
+</span>
+
+<span>
+ <i class="fas fa-donate" alt="Donate"></i>
+ <a href="https://blog.luevano.xyz/donate.html">Donate</a>
+</span>
+
+<span>
+ <i class="fas fa-rss" alt="RSS"></i>
+ <a target="_blank" href="https://blog.luevano.xyz/rss.xml">RSS</a>
+</span>
+
+<br>
+<span class="created-with">
+ <i class="fas fa-hammer" alt="Hammer"></i>
+ Created with <a href="https://github.com/luevano/pyssg">pyssg</a>
+</span>
+
+<br>
+<span class="copyright">
+ Copyright <i class="far fa-copyright" alt="Copyright"></i> 2023 David Luévano Alvarado
+</span>
+
+ </footer>
+ </body>
+</html> \ No newline at end of file