Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion FuncGodot Manual/pages/ref_fgd_resources.html
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ <h2 id="Base">FuncGodotFGDBaseClass</h2>
<h2 id="Solid">FuncGodotFGDSolidClass</h2>
<!--<p><img src="../images/ref_fgd_solid.png"></p>-->
<p>
FGD SolidClass entity definition that generates a mesh from <a href="ref_data.html#brush" target="main">Brush Data</a><br>.<br><br>
FGD SolidClass entity definition that generates a mesh from <a href="ref_data.html#brush" target="main">Brush Data</a>.<br><br>

A <i>MeshInstance3D</i> will be generated by FuncGodotMap according to this definition's Visual Build settings.
If <i>node_class</i> inherits <i>CollisionObject3D</i> then one or more <i>CollisionShape3D</i> nodes will be
Expand Down
1 change: 1 addition & 0 deletions FuncGodot Manual/pages/sidenav.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ <h3 class="sidenav">Tips and Tricks</h3>
<p class="sidenav">
<a href="tips_naming.html" target="main">Naming Patterns</a><br>
<a href="tips_worldspawn.html" target="main">Why Not Worldspawn?</a><br>
<a href="tips_material_based_footsteps.html" target="main">Material Based Footsteps</a><br>
<a href="tips_runtime_building.html" target="main">Runtime Map Building</a><br>
<a href="tips_multiple_models.html" target="main">Conditional Models in TrenchBroom</a>
</p>
Expand Down
69 changes: 69 additions & 0 deletions FuncGodot Manual/pages/tips_material_based_footsteps.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<!DOCTYPE html>
<html lang="en-US">

<head>
<title>FuncGodot Manual</title>
<link rel="icon" type="image/x-icon" href="../images/godot_ranger.svg">
<link rel="stylesheet" href="styles.css">
</head>

<body class="main">
<div class="main">
<h1>Material Based Footsteps</h1>
<p>
To do this we need to raycast in order to check what texture a face is so we can play an appropriate
sound effect such as snow sounds for snowy textures and stone sounds for stone textures.
</p>
<p>
Firstly, you will need a Raycast3D. Secondly, you will need a <a href="ref_fgd_resources.html#Solid" target="main">FuncGodotFGDSolidClass</a>. In the Mesh metadata
you will need to tick "Add Textures Metadata" found under Mesh Metadata. The collision mask for the Racyast3D must match a collision
layer of the FuncGodotFGDSolidClass, otherwise it will not report a collision.
</p>
<p>
Ticking "Add Textures Metadata" adds two metadata properties to generated nodes of that Solid Class. It adds "textures" which is
a PackedInt32Array, where the index in the array is the face index, and the value at any point is an
integer. This integer is then used by the "texture_names", the 2nd metadata property which is added.
Indexing that array with that integer gets us the texture name string. So how do I get the face index?
Raycast3D has a handy method called <code><a href="https://docs.godotengine.org/en/stable/classes/class_raycast3d.html#class-raycast3d-method-get-collision-face-index" target="_blank">get_collision_face_index()</a></code> which we use.
</p>
<blockquote><i>NOTE: If you are using <b>Jolt Physics</b> as your Physics Engine, you must tick Enable Ray Cast
Face Index in your project settings! This can be found in Project Settings > Physics > Jolt Physics 3D >
Queries > Enable Ray Cast Face Index. <a href="https://github.com/godot-jolt/godot-jolt/issues/702#issuecomment-2305670454" target="_blank">Enabling this has a non-trivial memory cost.</a></i></blockquote>
<p>Putting this all together, as a script on our Raycast3D, the following function returns the Texture Name when
we call it.</p>
<pre><code>func do_check() -> String:
var col := get_collider()
if !col:
return "" # No collision, no texture
if !col.has_meta("func_godot_mesh_data"):
return "" # Metadata not added
var metadata: Dictionary = col.get_meta("func_godot_mesh_data")
if !("textures" in metadata):
return "" # Textures Metadata not added
if !("texture_names" in metadata):
return "" # Textures Metadata not added
var textures: PackedInt32Array = metadata["textures"]
var texture_names: Array = metadata["texture_names"]
var texture: String = texture_names.get(
textures.get(
get_collision_face_index()
)
)
return texture;</code></pre>
<p>
When we call <code>do_check();</code>, we now get the texture String for the face the Raycast3D collided
with, if it collided with anything at all. The rest of the implementation of material based footsteps is
left as an exercise to the reader as it is project specific, but you will likely want some way to convert
from a texture name to a Stream and to then play that Stream with an AudioStreamPlayer.
</p>
<p>
As a note you can also use this same approach for running code on specific textures. For example damage on
lava textures, slowness on cobweb textures, though these may be better accomplished with a
FuncGodotFGDSolidClass that creates an Area3D instead. You can also use this to get material-specific decal
textures.
</p>
</div>
<br><br><br>
</body>

</html>
12 changes: 0 additions & 12 deletions FuncGodot Manual/pages/tips_worldspawn.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,6 @@ <h2 id="OcclusionCulling">Occlusion Culling</h2>
In exchange for full automation, FuncGodot instead gives you full control.
</p>

<h2 id="SurfaceMaterials">Surface "Materials"</h2>
<p>
A common question a lot of Godot devs have is <i>how do I get the texture of the surface my character is stepping on or shooting?</i> and the answer is... you don't!
Well, the short answer anyway. Since Godot's CollisionObjects are completely separate from the MeshInstance3Ds, there's no real good performant way to actually
do it surface by surface. Any possible solutions that involve getting the stage mesh's texture on a particular face are just not worth it. But why work against the
engine when you can work <i>with</i> it?
</p>
<p>
If we can control how our stage geometry is split up, we can also provide that stage geometry with key value properties, including one that supplies a <i>Material Type</i>
that can easily be passed to any character stepping on or shooting it. This is something that can't be done with a singular Worldspawn entity.
</p>

<h2 id="LiveWithoutWorldspawn">How Do I Live Without Worldspawn?</h2>
<p>
You'll want to create a <a href="ref_fgd_resources.html#Solid" target="main">Solid Class entity</a> that matches the <i>Worldspawn</i> entity definition.
Expand Down