diff options
author | David Luevano Alvarado <david@luevano.xyz> | 2023-08-29 04:17:09 -0600 |
---|---|---|
committer | David Luevano Alvarado <david@luevano.xyz> | 2023-08-29 04:17:09 -0600 |
commit | e6fb8b69c85894994d649b4c7c59a6a1fa606c34 (patch) | |
tree | da723dabaac5128634eddeecf9f982f899f604cf /live | |
parent | 06184c13af639917e1af5a1bc298b0022c1398ea (diff) |
add godot layer notes
Diffstat (limited to 'live')
-rw-r--r-- | live/blog/g/flappybird_godot_devlog_2.html | 10 | ||||
-rw-r--r-- | live/blog/g/godot_layers_and_masks_notes.html | 164 | ||||
-rw-r--r-- | live/blog/index.html | 1 | ||||
-rw-r--r-- | live/blog/rss.xml | 26 | ||||
-rw-r--r-- | live/blog/sitemap.xml | 8 | ||||
-rw-r--r-- | live/blog/tag/@english.html | 1 | ||||
-rw-r--r-- | live/blog/tag/@gamedev.html | 1 | ||||
-rw-r--r-- | live/blog/tag/@gdscript.html | 1 | ||||
-rw-r--r-- | live/blog/tag/@godot.html | 1 |
9 files changed, 209 insertions, 4 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">¶</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’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’t ask to convert anything so probably nowadays the conversion is better. Godot’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">¶</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’s collision layers and masks (will refer to them just as layers) I thought I understood them only to find out that they’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… well, detecting.</p> +<p>At the end of the day the issue wasn’t that the layers weren’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’t understand layers that well or else I would’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’s mask and object’s mask are set to <code>0</code> (i.e. no layers), they will still collide with the player, because the player’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 & B.layers || B.mask & A.layers</code>, where <code>&</code> is bitwise-and, and <code>||</code> is the or operator. I.e. it takes the layers that correspond to the other object’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 diff --git a/live/blog/index.html b/live/blog/index.html index 62e68e7..6b32ad9 100644 --- a/live/blog/index.html +++ b/live/blog/index.html @@ -88,6 +88,7 @@ <h2>Articles</h2> <ul class="page-list"> <h3>2023</h3> + <li><span class="page-list-item">Aug 29</span> - <a href="https://blog.luevano.xyz/g/godot_layers_and_masks_notes.html">Godot layers and masks notes</a></li> <li><span class="page-list-item">Aug 27</span> - <a href="https://blog.luevano.xyz/g/flappybird_godot_devlog_2.html">Porting the FlappyBird clone to Godot 4.1 devlog 2</a></li> <li><span class="page-list-item">Aug 20</span> - <a href="https://blog.luevano.xyz/a/pastebin_alt_with_privatebin.html">Set up a pastebin alternative with PrivateBin and YOURLS</a></li> <li><span class="page-list-item">Jul 24</span> - <a href="https://blog.luevano.xyz/a/jellyfin_server_with_sonarr_radarr.html">Set up a media server with Jellyfin, Sonarr and Radarr</a></li> diff --git a/live/blog/rss.xml b/live/blog/rss.xml index 82a3256..e646e8e 100644 --- a/live/blog/rss.xml +++ b/live/blog/rss.xml @@ -23,6 +23,30 @@ <link>https://blog.luevano.xyz</link> </image> <item> + <title>Godot layers and masks notes</title> + <link>https://blog.luevano.xyz/g/godot_layers_and_masks_notes.html</link> + <guid isPermaLink="true">https://blog.luevano.xyz/g/godot_layers_and_masks_notes.html</guid> + <pubDate>Tue, 29 Aug 2023 10:10:06 GMT</pubDate> + <category>English</category> + <category>Gamedev</category> + <category>Gdscript</category> + <category>Godot</category> + <description>Some notes I took regarding Godot's confusing collision layers and masks.</description> + <content:encoded><![CDATA[<p>The first time I learned about Godot’s collision layers and masks (will refer to them just as layers) I thought I understood them only to find out that they’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… well, detecting.</p> +<p>At the end of the day the issue wasn’t that the layers weren’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’t understand layers that well or else I would’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’s mask and object’s mask are set to <code>0</code> (i.e. no layers), they will still collide with the player, because the player’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 & B.layers || B.mask & A.layers</code>, where <code>&</code> is bitwise-and, and <code>||</code> is the or operator. I.e. it takes the layers that correspond to the other object’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>]]></content:encoded> + </item> + <item> <title>Porting the FlappyBird clone to Godot 4.1 devlog 2</title> <link>https://blog.luevano.xyz/g/flappybird_godot_devlog_2.html</link> <guid isPermaLink="true">https://blog.luevano.xyz/g/flappybird_godot_devlog_2.html</guid> @@ -60,7 +84,7 @@ </ul> </div> <h2 id="porting-to-godot-4">Porting to Godot 4<a class="headerlink" href="#porting-to-godot-4" title="Permanent link">¶</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’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’t ask to convert anything so probably nowadays the conversion is better. Godot’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">¶</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> diff --git a/live/blog/sitemap.xml b/live/blog/sitemap.xml index 0f0ece6..7131e1d 100644 --- a/live/blog/sitemap.xml +++ b/live/blog/sitemap.xml @@ -46,8 +46,14 @@ </url> <url> + <loc>https://blog.luevano.xyz/g/godot_layers_and_masks_notes.html</loc> + <lastmod>2023-08-29</lastmod> + <changefreq>weekly</changefreq> + <priority>1.0</priority> + </url> + <url> <loc>https://blog.luevano.xyz/g/flappybird_godot_devlog_2.html</loc> - <lastmod>2023-08-28</lastmod> + <lastmod>2023-08-29</lastmod> <changefreq>weekly</changefreq> <priority>1.0</priority> </url> diff --git a/live/blog/tag/@english.html b/live/blog/tag/@english.html index 2f98448..10f4aef 100644 --- a/live/blog/tag/@english.html +++ b/live/blog/tag/@english.html @@ -78,6 +78,7 @@ <h2>Articles</h2> <ul class="page-list"> <h3>2023</h3> + <li><span class="page-list-item">Aug 29</span> - <a href="https://blog.luevano.xyz/g/godot_layers_and_masks_notes.html">Godot layers and masks notes</a></li> <li><span class="page-list-item">Aug 27</span> - <a href="https://blog.luevano.xyz/g/flappybird_godot_devlog_2.html">Porting the FlappyBird clone to Godot 4.1 devlog 2</a></li> <li><span class="page-list-item">Aug 20</span> - <a href="https://blog.luevano.xyz/a/pastebin_alt_with_privatebin.html">Set up a pastebin alternative with PrivateBin and YOURLS</a></li> <li><span class="page-list-item">Jul 24</span> - <a href="https://blog.luevano.xyz/a/jellyfin_server_with_sonarr_radarr.html">Set up a media server with Jellyfin, Sonarr and Radarr</a></li> diff --git a/live/blog/tag/@gamedev.html b/live/blog/tag/@gamedev.html index 512bd9c..b4141f6 100644 --- a/live/blog/tag/@gamedev.html +++ b/live/blog/tag/@gamedev.html @@ -78,6 +78,7 @@ <h2>Articles</h2> <ul class="page-list"> <h3>2023</h3> + <li><span class="page-list-item">Aug 29</span> - <a href="https://blog.luevano.xyz/g/godot_layers_and_masks_notes.html">Godot layers and masks notes</a></li> <li><span class="page-list-item">Aug 27</span> - <a href="https://blog.luevano.xyz/g/flappybird_godot_devlog_2.html">Porting the FlappyBird clone to Godot 4.1 devlog 2</a></li> <h3>2022</h3> <li><span class="page-list-item">Jun 10</span> - <a href="https://blog.luevano.xyz/g/gogodot_jam3_devlog_1.html">Creating my Go Godot Jam 3 entry using Godot 3.5 devlog 1</a></li> diff --git a/live/blog/tag/@gdscript.html b/live/blog/tag/@gdscript.html index f004012..3866b7c 100644 --- a/live/blog/tag/@gdscript.html +++ b/live/blog/tag/@gdscript.html @@ -78,6 +78,7 @@ <h2>Articles</h2> <ul class="page-list"> <h3>2023</h3> + <li><span class="page-list-item">Aug 29</span> - <a href="https://blog.luevano.xyz/g/godot_layers_and_masks_notes.html">Godot layers and masks notes</a></li> <li><span class="page-list-item">Aug 27</span> - <a href="https://blog.luevano.xyz/g/flappybird_godot_devlog_2.html">Porting the FlappyBird clone to Godot 4.1 devlog 2</a></li> <h3>2022</h3> <li><span class="page-list-item">Jun 10</span> - <a href="https://blog.luevano.xyz/g/gogodot_jam3_devlog_1.html">Creating my Go Godot Jam 3 entry using Godot 3.5 devlog 1</a></li> diff --git a/live/blog/tag/@godot.html b/live/blog/tag/@godot.html index fd622f7..a5f2d67 100644 --- a/live/blog/tag/@godot.html +++ b/live/blog/tag/@godot.html @@ -78,6 +78,7 @@ <h2>Articles</h2> <ul class="page-list"> <h3>2023</h3> + <li><span class="page-list-item">Aug 29</span> - <a href="https://blog.luevano.xyz/g/godot_layers_and_masks_notes.html">Godot layers and masks notes</a></li> <li><span class="page-list-item">Aug 27</span> - <a href="https://blog.luevano.xyz/g/flappybird_godot_devlog_2.html">Porting the FlappyBird clone to Godot 4.1 devlog 2</a></li> <h3>2022</h3> <li><span class="page-list-item">Jun 10</span> - <a href="https://blog.luevano.xyz/g/gogodot_jam3_devlog_1.html">Creating my Go Godot Jam 3 entry using Godot 3.5 devlog 1</a></li> |