The article is relevant to my last post, Godot: Texture, Grid Map, Move And Rotate.
I want to create a 3D game by Godot, here are some notes about it.
All files in the project are uploaded to GitHub: https://github.com/theArcticOcean/SimpleTools/tree/master/godotGame/NumberGameIn3D
Add Music And Play
Create a new node container to manage all audio streams.
Add an AudioStreamPlayer3D child node, load ogg file for its Stream. Adjust the parameters Unit Size and Max Db to get a better sound effect.
Add a test key and play our audio by it.
Add playing code.
func _physics_process( delta ):
if Input.is_action_pressed("test_key"):
var player:AudioStreamPlayer3D = musicContainer.get_node( "explose" ).d
uplicate()
player.stream = player.stream.duplicate()
player.stream.loop = false
player.global_transform.origin = $player/Camera.global_transform.origin
player.play()
$"/root".add_child( player )
Put Camera’s View To A Mesh’s Surface
Create a MeshInstance and generate a cube as mesh object. Add Viewport and its child node, the new Viewport object has its child node which is a Camera object.
We mark the flag Current
of the camera true
to use the camera in the ancestor viewport.
Then we need to create a shader material for our wall. Material – Create ShaderMaterial – click shader and edit, add the following code for the it.
shader_type spatial;
render_mode unshaded;
uniform sampler2D refl_tx;
void fragment(){
ALBEDO = texture( refl_tx, vec2(1.0 - SCREEN_UV.x, SCREEN_UV.y) ).rgb;
}
Finally, make sure the resource local to scene and create a new viewport texture which connects child node Viewport for Refl tx.
Game address:
[…] 3D Game Notes: Add Music And Show Camera View On Mesh Surface Categorypuzzle […]
[…] 3D Game Notes: Add Music And Show Camera View On Mesh Surface Categories: puzzle game Tags: puzzle game […]
[…] 3D Game Notes: Add Music And Show Camera View On Mesh Surface […]
[…] 3D Game Notes: Add Music And Show Camera View On Mesh Surface […]