A few updates - problems

Hello,
I have finished the 3D game course and I would like to improve it in some aspects but I need help. I have been searching on the internet but I can’t get my head around it.
I have successfully added the following:
1.- I have added background music to the game. This is what I have achieved.
2.- Start screen and screen where the controls are shown.
I have not achieved the following:
1.- I wanted to add shooting sound but I get it with a weapon but it gives me error when I change weapon and I can’t get it to work.
2.- When you reach the end there is something that indicates that you have finished with a congratulation screen or something like that. I have tried to add an Area3D and a CollisionShape3D making the connection with the Bodyentered node but I can not get it to work.
Can you help me please?

Congratulations on finishing the course and trying some extensions! That’s a great way to continue learning more.

Regarding the issues, posting the relevant code would of course be helpful, but here are a few things you can try in the meantime as well:

    1. Does the sound work with the first weapon and only stop working when you change weapons?
    • If so, check that you are updating your sound reference when you change weapons. You are probably best off making a dictionary of sound references, and then storing the current sound as a separate variable whenever a weapon is equipped. That way, you’re not searching through a dictionary every time you fire the weapon.
    • If not, then you need to check that your sound is loading correctly. As a quick test, try just playing the sound as soon as you start the game and make sure that works.
    1. I experienced something like this while working on an extension for Barbarian Blaster. Put some print statements in and around that code and see what you find; in my case, I discovered that this event was returning just the collider instead of the actual object, so I had to use collider.get_parent() to return a reference to what I wanted. See what your print statements tell you about what’s happening there.

Good luck =)

(also, I saw your other question about exporting, and unfortunately I have no idea what would cause that).

1 Like

Hi. Thanks for your reply. Yes, the sound works with the first weapon and the error appears when I change weapon.
I don feel confident still to implement the dictionary and use it properly without help. I have use dictionaries in Python at basic level and what I have learned in this course.
I copy and paste the weapon handler script + the shoot function. If you can help me brilliant, if not… do not worry.
WeaponHandler:
extends Node3D

@export var weapon_1: Node3D
@export var weapon_2: Node3D

func _ready() → void:
equip(weapon_1)

func _unhandled_input(event: InputEvent) → void:
if event.is_action_pressed(“weapon_1”):
equip(weapon_1)
if event.is_action_pressed(“weapon_2”):
equip(weapon_2)
if event.is_action(“next_weapon”):
next_weapon()
if event.is_action_pressed(“last_weapon”):
last_weapon()

func equip(active_weapon: Node3D) → void:
for child in get_children():
if child == active_weapon:
child.visible = true
child.set_process(true)
child.ammo_handler.update_ammo_label(child.ammo_type)
else:
child.visible = false
child.set_process(false)

func next_weapon() → void:
var index = get_current_index()
index = wrapi(index + 1, 0, get_child_count())
equip(get_child(index))

func last_weapon() → void:
var index = get_current_index()
index = wrapi(index - 1, 0, get_child_count())
equip(get_child(index))

func get_current_index() → int:
for index in get_child_count():
if get_child(index).visible:
return index
return 0

func get_weapon_ammo() → AmmoHandler.ammo_type:
return get_child(get_current_index()).ammo_type

Shoot function
Shoot func

func shoot() → void:
if ammo_handler.has_ammo(ammo_type):
ammo_handler.use_ammo(ammo_type)
muzzle_flash.restart()
cooldown_timer.start(1.0 / fire_rate)
var collider = ray_cast_3d.get_collider()
weapon_mesh.position.z += recail
if ray_cast_3d.is_colliding():
if collider is Enemy:
collider.hitpoints -= weapon_ddamage
var spark = sparks.instantiate()
add_child(spark)
spark.global_position = ray_cast_3d.get_collision_point()



No worries about the dictionary; I think I got ahead of myself a bit because of the way I’m doing it in my own project. Also, that will come with practice =)

I’m not seeing any code involving sound references or sound playing in what you posted. Where are your AudioStreamPlayers, how do you fill their Stream fields, and where do you play them? I wonder if this might be as simple as an export variable not being filled or something like that.

I’ll apologise just now, I’m on phone only as my laptop is having a disagreement with works WiFi :frowning:

I was having a play around to make it modular.

In the hitscanweapon scene i added an empty audiostreamplayer (not the 3d one)

In the hitscan script, I added this at top

Then I added this to the end of the shoot method.

If you go to the player scene now you should be able to drag sfx for each weapon into the inspector.

Hope that helps a bit.

Again sorry I’ve only got phone atm :frowning:

2 Likes

@OboShape’s solution is pretty much exactly what I would have done :+1:

My earlier suggestion with the dictionary is just an alternative to @export variables - that’s just the first place my head goes when it comes to audio files. Definitely not necessary =)

1 Like

I do like a good dictionary for straight forward access to lookups that arrays just aren’t very performance at :slight_smile:

1 Like

Hi,
No, sorry, I removed my code as it was not working.

Hi @OboShape
Do not apologise please. Thanks a lot for taking your time to answer me. I am with my phone at the moment so I will try your solution as soon as possible.
Thanks again @BH67 and @OboShape for all your help.
Let’s see if I am able to implement it myself :grin:

1 Like

Hi guys,
I implemented your suggestions and the game is not giving me any error messages but the weapon is not producing any sound in any of the weapons.
I attached a few screenshots with the implementation and I compress the game to share it with you.
Screenshots
1 - Hitscanweapon script
2 - Shoot method
3 - Shoot method with the extra code with different indentation
4 / 5 - Rifle and the other weapon inspector view with the audio file
6 - Game music in the main scene
I removed the node in for the game music en in the game scene also to see if that was the problem but still does not work. I am sure that it is something very silly but…







GAME FILES COMPRESSED

got it, totally my fault, when i was testing, i dragged the audio file into the sfx player for each weapon, rather than using the exported variable to assign it to the audio player.

if you add this to the hitscan weapon, it will assign the stream to the player. sorry.

func _ready() -> void:
	sfx_player.stream = sfx_bullet

also, if you indent the play SFX lines shown below in the shoot method, one more to the right, it will only play the sound, if the ammo handler has ammo.

if sfx_player.stream != null:
			sfx_player.play()

might want to have a look at getting some smaller .ogg sound clips, as theyre quite big as wav files (150k as opposed to an ogg which is 1 to 2k), the sound isnt syncing up as it takes a while to play.

for the sound files i used in testing, in the editor, go to the asset lib tab and search for Kenney Impact Sounds.
theyre all CCO and .ogg files, so really small and free.

the two files i used from that pack were these two, theyre short, small and will be able to keep up with the firing.

image
the plate heavy 4 for the rifle and the 000 for the smg.

apologies again :frowning:

for the end level area collision. the signal method is missing from the player script that you have connected.

func _on_end_level_trigger_body_entered(body: Node3D) -> void:
	if body.name == "Player":
		print("Game Ended")

you could use collision layers here to only check for the Player entering, as currently it triggers on all collision shapes entering it, and it triggers straight away with the floor tile.

or you could add a class_name to the player and check
if body is Player:
but for now, ive just popped this in to check the current name of the player node, just to get it working.

Hi,
Thank you so much!!!
Everything works
I implemented a End Game Screen similar to the Game over screen at the End of the game.
I feel that, as much as I learned, little I know.
I will appreciate if you can find the problem of exporting the game.
It is working very well on my computer but I would like to exported to upload the project into my itch.io account as I have done will all the other projects but it is not working properly. The main scene is not working properly. I attached a video to explain the problem in another ticket/question.
I have the same problem without the Screen menu. I upload the project as it was finished after the course to see if the problem was because something I did with the menu but it is not.
Kind Regards

I’ve seen the other post and that was on my radar to look at.
I have your project just now.
I’ve not tried to upload to itch, but ill have a read up.
There’s another platform I use as well specifically for godot.

I’ll give it a read up to see if I can learn how it’s done and get back to you.

I took a stab at it and managed to get it mostly working on Itch; it’s something to do with WebGL not liking the multiple cameras. Workaround is to enable Layer1 (+ Layer 2) on WeaponCamera’s Cull Mask.

More details on that topic; maybe you’ll have additional insight based on this =)

Thank you very much!!!

Thanks a lot!! I will try it As soon as I can.

1 Like

Hi,
I use itch.io because I do not know any other but I don’t mind to use another but also, I am learning, so I would like to learn how to solve this problems.
Thanks again in advance

1 Like

the other gotm site that i used to use has now shut down.

the web player issue, seems to revolve around the sub viewport container.
there is a bug currently when a transparent BG is enabled and enabling SSR causes a somilar issue where the subviewport and skybox are shown and noting else.

i think for anything using a subviewport, its possible that we might just have to enabled it as a downloadable exe in itch.

ill keep digging.

Hi,
Thanks a lot for your helps and comments.
I did both options. It is true that the web version is not perfect because, as you know, the weapon con go inside the buildings but… At least it can be played online.
I also exported in the windows option as executable but I can tested as I used a Mac computer. I have a windows virtual machine but still don’t work. I do not know if I have done something wrong or it is because my virtual machine does not allow to run it.
I share the link here: https://crookedspaniard.itch.io/galactic-assault
Ps: I uploaded in the Mac version too and that one is working alright.
Kind Regards

1 Like

Privacy & Terms