summaryrefslogtreecommitdiff
path: root/live/blog/g/godot_layers_and_masks_notes.html
diff options
context:
space:
mode:
Diffstat (limited to 'live/blog/g/godot_layers_and_masks_notes.html')
-rw-r--r--live/blog/g/godot_layers_and_masks_notes.html170
1 files changed, 0 insertions, 170 deletions
diff --git a/live/blog/g/godot_layers_and_masks_notes.html b/live/blog/g/godot_layers_and_masks_notes.html
deleted file mode 100644
index 1d55d97..0000000
--- a/live/blog/g/godot_layers_and_masks_notes.html
+++ /dev/null
@@ -1,170 +0,0 @@
-<!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="next">
- <a href="https://blog.luevano.xyz/g/flappybird_godot_devlog_3.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">
- <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