Looks like you're not logged in

Login or Register to continue

Lesson Q&A

Use this space for questions related to what you're learning. For any other type of support (website, learning platform, payments, etc...) please get in touch using the contact form.

  • Changing particle rotation in codeimperturbable-reindeerI'm trying to make a bullet that has a GPUParticle2D nod that creates particles trailing behind it. I'm using the zap.png file as the texture and trying to get the particle to rotate in the direction the bullet is traveling. So far I have not been able to change the particles' angle in code. I have tried using the set_param_min() and set_param_max methods to the best of my understanding: ```gdscript _gpu_particles_2d.process_material.set_param_max(7,rotation) _gpu_particles_2d.process_material.set_param_min(7,rotation) ``` and while I don't get any errors, it doesn't have an effect. How do I achieve my goal? 4 0 Jun. 13, 2025
  • Stuck Making the Ice bullets.pikminfan71Hello! Iv'e been working on the ice bullets and for some reason the bullets Don't scale when the player holds the Input.. I'm not sure if I just made it the wrong way or something. Also, When I shoot the ice bullets specifically while aiming down they shoot and vanish immediatelly which is very weird. I would love some help, thank you! WEAPON SCRIPT: ```gdscript ## Base class for weapons class_name Weapon extends Node2D ## The bullet type the weapon will fire, If the variable is null, ## The weapon will instantiate the base bullet scene. @export var bullet_type: PackedScene = null ## the speed in which the bullet will go, lower values will make the bullet ## feel unnatural so I wouldn't advise... @export_range(100.0, 2000.0, 1.0) var bullet_speed : float = 1200 ## The amount of damage the Bullet will cause. Higher values may make ## the mobs die to easily... @export_range(1,5, 1) var bullet_damage := 1 ## The range the bullet will go, when the bullet reaches or passes the value, ## it will queue_free @export_range(200.0, 3000.0, 1.0) var bullet_max_range : float = 400 ## The random angle added to the bullet's trajectory, increasing this number ##makes the weapon less accurate @export_range(0.0, 360.0, 1.0, "radians_as_degrees") var random_added_angle := PI / 12.0 ## The shooting sound of the weapon @export var shooting_sound: AudioStreamPlayer2D = null ## the cool down timer makes it so the player won't be able to shoot bullets ## continuesly. provides a minor cooldown between bullets. @onready var cool_down_timer: Timer = %CoolDownTimer ## takes the SHOOT Input from the player, and if the cool down timer is ## stopped, will call the _shoot function and start the cool down timer. func _physics_process(delta: float) -> void: if Input.is_action_just_pressed("SHOOT") and cool_down_timer.is_stopped(): _shoot() cool_down_timer.start() ## checks if there is a bullet scene in the bullet type variable, if not, assigns ##the base bullet scene to the variable. Then instantiates the bullet, adds it ## to the scene and assigns the global position and rotation to the weapon's. ## assigns the bullet speed and max range to the bullet's equivelent variables ## and adds to it's rotation the added angle in a random range. Then, if there is ## a shooting sound, it will play it. func _shoot(bullet_scale_multiplier: int = 1, amount_of_bullets: int = 1) -> void: if not bullet_type: bullet_type = preload("res://weapons/bullets/bullet.tscn") for bullet_to_shoot in amount_of_bullets: var bullet := bullet_type.instantiate() get_tree().current_scene.add_child(bullet) bullet.scale *= bullet_scale_multiplier bullet.global_position = global_position bullet.global_rotation = global_rotation bullet.speed = bullet_speed bullet.damage = bullet_damage bullet.max_range = bullet_max_range #we add to the global rotation of the bullet a random angle between minus half of random_added_angle and half of random_added_angle bullet.global_rotation += randf_range(-random_added_angle / 2.0, random_added_angle / 2.0) if shooting_sound: shooting_sound.play() ``` HERE is the ICE WEAPON script! ```gdscript extends Weapon @onready var charging_shot_timer: Timer = $ChargingShotTimer func _ready() -> void: bullet_type = preload("res://weapons/bullets/ice_bullet.tscn") func _physics_process(delta: float) -> void: if Input.is_action_pressed("SHOOT"): charging_shot_timer.start() if Input.is_action_just_released("SHOOT") and charging_shot_timer.is_stopped(): _shoot(2) if Input.is_action_just_released("SHOOT") and not charging_shot_timer.is_stopped(): _shoot(1) ``` Thank you so much! 9 0 May. 26, 2025
  • I got really stuck!AJ StudiosI have spent quite some time reading about resources and went back to the lesson 'Creating Health Pickups'. It did helped me a lot understanding how the Pickup scene is setup, but I got stuck when It comes to creating new bullet pickups. Should I create a new script called (for example) `fire_spray.gd` with a **class_name** `FireSpray` that extends **Item**? Then right click in the File System and create a new **resource** called `fire_spray.tres` from that script? I am very confused on the steps I need to take and don't know how to continue. If you guys can guide me on how to create a new pickup for a different weapon and connect the new weapon functionality when the player picks it up, I can create the rest of the bullet pickups. I would really appreciate it since I am really stuck on this one. Here's my attempt at explaining this a bit better: [https://www.youtube.com/watch?v=czwuxA06UZY](https://www.youtube.com/watch?v=czwuxA06UZY) **Note**: Let me know if you need me to include the project folder. 7 0 May. 11, 2025
  • Question on resources and inheritanceilliterate-spiderI personally like resources. Not only is it very fun for me but I get the idea alot better. Honestly i still dont know how to use the script after overriding it. Anyways my question is if I master resources very well would I still need to use inheritance? Even if inheritance is better for simple games with not alot of levels or items/weapons. Thanks in advance! 2 0 Apr. 24, 2025
  • Stuck lolilliterate-spiderHi I am taking my time on this one and thinking really hard. Trying to implement the array of weapon scenes and switching them from the weapon node on the player. What I used and what i got so far. ```gdscript var weapons : Array[PackedScene]= [preload("res://weapons/charged_ice.tscn"), preload("res://weapons/continuous_fire.tscn"), preload("res://weapons/shotgun.tscn")] func _physics_process(delta: float) -> void: .... if Input.is_action_just_pressed("gun_1"): weapon.queue_free() var continue_fire = weapons[0].instantiate() weapon_anchor.add_child(continue_fire) elif Input.is_action_just_pressed("gun_2"): weapon.queue_free() var shotgun = weapons[1].instantiate() weapon_anchor.add_child(shotgun) ``` 1. So gun_1 works fine no problem if I switch from gun_1 to gun_2 then I get cannot call method 'queue_free' on a previously freed instance. im guessing you cannot queue free back to back then. 2. Also if I used gun_2 from the start it switches fine but it wont shoot. I used your firespray script just to see if my gun_2 would work it didnt Can I get hint or a direction on where to look? Thanks guys =D 4 0 Apr. 22, 2025
  • Weapon Swap Trouble (and resolution?)chubby-frogI have been stuck on trying to resolve this for the past couple days on my own, but I keep hitting a dead end because I don't think I understand what is happening behind the scenes. 1. I created the autofire weapon from this lesson extending the Weapon class 2. I created in the Player script an array of the two weapons (regular and autofire), a weapon toggle Input, and a function to add and remove the weapons in the order of the array to cycle through them (swapping weapons scenes instead of just only scripts) **The problem**: I get the following errors when I try to run the LEVEL scene and click the shoot button, (the bullets are currently coded from the previous lessons to instantiate to the "current scene". This error does not occur when running the PLAYER Scene for some reason, so I assumed the code logic of the weapon switch was working properly. -E 0:00:00:940 weapon.gd:17 @ shoot_bullet(): Failed to instantiate scene state of "", node count is 0. Make sure the PackedScene resource is valid. -E 0:00:00:940 weapon.gd:18 @ shoot_bullet(): Parameter "p_child" is null. I noticed that the moment I started instantiating the weapons from the Player script, there were issues with instantiating the bullets to the current scene *when the current scene is the Level*. I even tested starting the player without any weapons, and only instantiating the regular weapon on the ready function of the Player script while running the LEVEL scene--same error. The one thing that worked for me is putting all of the scenes and scripts in the same folder, in which moving the level scene ***to*** ***the player folder*** actually allowed the scene to run properly. I had remembered from the Lesson 5:7 there was the warning to make sure: **The code assumes that the `gem.tscn` file is in the same folder as the script. If you get an error, make sure the `gem.tscn` file is in the same folder as the `random_item_placer.gd` script.** To my understanding, the preloaded scene needed to be in the same folder as the script that it was being instantiated from. But in this case, the WEAPON script is instantiating the bullets and adding as children to the LEVEL scene -----So my final question is, does the ***destination*** scene (node that will have the instantiated scene as a child) have to be in the same folder as the script that is instantiating the scene and scene being instantiated: 1. bullet scene being instantiated in weapon script, added as child of LEVEL (current scene) 2. Weapon Scene being the script where instantiation is coded and home of the preloaded bullet scene reference 3. Player script being where weapons are preloaded and instantiated from, to the anchor as the parent (this caused the error in the first place) Right now I have all the scenes and scripts involved in the weapon switch in the same folder, which is working, but not sure what is absolutely required? If the file location actually has a major affect on this, I am starting to think that it might be smarter to organize by file type than by game systems--or if even that method of organizing would have its limitations for something like this? 2 0 Apr. 06, 2025
  • My solution to Ice charge weaponsSootyHere is my solution to the challenge. After checking the solution, I didn't like how if you had a time of 3 and a damage of 2 , the result would be 8. So I modified it. It seems to work watching the numbers being output in the console ```gdscript extends Weapon var current_charge : float = 0.0 var charge_value : float = 1.0 var max_charge : float = 3.0 var charge_damage : float = 2.0 @onready var gpu_particles_2d: GPUParticles2D = %GPUParticles2D func _physics_process(delta: float) -> void: if Input.is_action_pressed("action_shoot"): gpu_particles_2d.emitting = true if current_charge < max_charge: current_charge += clampf(charge_value,0.0,max_charge) * delta print(current_charge) if Input.is_action_just_released("action_shoot"): gpu_particles_2d.emitting = false _shoot() current_charge = 0 func _spawn_bullet ()-> void: var _new_bullet : Node = bullet_scene.instantiate() get_tree().current_scene.add_child(_new_bullet) if current_charge < 1.0: current_charge = 1.0 _new_bullet.damage = floor(charge_damage * current_charge) print(_new_bullet.damage) _new_bullet.global_position = global_position _new_bullet.global_rotation += global_rotation _new_bullet.max_range = max_range _new_bullet.speed = speed _new_bullet.scale = Vector2.ONE * current_charge _new_bullet.rotation += randf_range(-random_angle/2.0, random_angle/2.0) ``` 3 0 Mar. 23, 2025
  • Issue with second weaponkazaHi! I'm getting little confused on creating a second weapon. Here is the thing: - I've created the second scene, a copy of weapon scene and I keep the main node (Node2D) with two sprites (of hands), I put a Timer, but I attached a new script on the root node that extends of Weapon and inside it i've coded only the _*physics*_proccess. What happens is that regardless i don't instantiate the second weapon, same way the engine is calling _*physics*_process of the secondary weapon. I'm doing something wrong? What i miss? Tks in advance. 8 0 Feb. 23, 2025
  • Why divide the max_spread_angle by 2?silent-meerkatwhy did you do randf_range(-max_spread_angle / 2.0, max_spread_angle / 2.0) instead of setting the max_spread_angle to PI/6 ? 1 0 Feb. 17, 2025
  • What is a good way of creating ice bulletsperiodic-spoonbillPersonally I created a new node with the same system as the 'normal' bullets (but with different sprites and sounds) and then I attached the same script as the 'normal' bullets to it. It seems a bit makeshift, so not sure if that's a good way to do it or if I should have just made bullet more generalised. 3 0 Feb. 06, 2025
  • How do I use the created scripts?ram876Hello! I have a problem understanding the assignment. In the challenges, you prompt to create a script and write the logic of a new weapon there. I have 2 questions. 1) If I'm only writing a script with new logic, how do I use it when shooting? In this case, do I need to create an exported variable for the weapon, first removing it from the player's scene, and then, when selecting pickups, load this script using load/preload? 2) Judging by your examples of solving challenges, you have created not only a script, but a whole scene with your script. Did you mean that in the challenges? 6 0 Jan. 06, 2025
  • Accessing nodes elsewherePaulI decided to spice up the automatic shooting weapon by making it fire really fast but have a heat build-up mechanic. I got this to work but I think I've either forgotten an important lesson or I've not fully understood accessing/getting references to nodes elsewhere in the scene tree. Here's a short demo of what I mean: [https://youtu.be/Tc7qLQdVm4g?si=plzQ8L76fkHdBHau](https://youtu.be/Tc7qLQdVm4g?si=plzQ8L76fkHdBHau) So, it works. I want the 'heat' `ProgressBar` node part of the Player, alongside the health bar in my node structure, but I want to handle the overheating mechanics in the weapon with the rest of the weapon code, nested deeper down in the Player scene. I was struggling to work out the best way to do this - it seems like a simple thing but for some reason I'm puzzled by it. I got it to work using: ```gdscript @onready var heat_bar: ProgressBar = get_node("../../../HeatBar") ``` to get a reference to the heat bar from the weapon (up several levels, then across). Would this be the best way to achieve this? By using a relative path rather than absolute, it certainly seems less prone to breaking later on, but I'm still not sure if this would be the recommended method. 2 0 Dec. 31, 2024
  • An error in the bullet spread scriptKetanI noticed that in the "shotgun" version of the weapon wasn't playing any sound when shooting and I did some research, apparently the `shoot_audio` var was always null Turns out you can't access export variables from an extended scene, I tried to load it at runtime but Godot at the moment doesn't support loading .wav files at runtime The only solution I found was to add a new @onready var in the shotgun weapon scene with a new AudioStreamPlayer node, I'm curious if the there're any other ways I could solve this? 2 0 Dec. 24, 2024
  • Charging Ice ParticlesMarcJI've added the charging particles for the ice fist but when I looked at your version of the code I see you used an AnimationPlayer to start the particles. I assumed that you used it to intensify the particles as you charge but when I tried it I found that the particles restarted if you changed any of the values and from a bit of reading it seems that's the expected behavior. So I'm just curious to know what you are doing with the AnimationPlayer? 6 0 Dec. 22, 2024
Site is in BETA!found a bug?