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.

  • Confused about rotation and global rotation GearheadgeekHello! I'm going back through the scripts I wrote to make sure I understand them, and I cannot wrap my head around the differences between rotation and global rotation. I must have looked at the hints when implementing bullet spread because the feature works, but when I fiddle with it, it doesn't behave as I expect it to. Setting the instantiated bullets' global rotation to the same as the weapon makes sense to me--if they're given the same rotations, they'll both point at the same thing: feature achieved. But, why doesn't anything happen if I try to += my randomized spread value to the bullets' global rotation, but it works when I add it to the bullets' local rotation? Aren't both values rotations that can be modified/both are full circles represented by 2 * PI, no? Am I misunderstanding local vs global frames of reference? 5 2 Mar. 05, 2025
  • Is there any benefit in not using func _input()?milk_manWhen I did the challenges I used the following code for calling the shoot function: ```gdscript func _input(event: InputEvent) -> void: if event.is_action_pressed("shoot"): shoot() ``` instead of: ```gdscript func _physics_process(_delta: float) -> void: if Input.is_action_just_pressed("shoot"): shoot() ``` Now I understand that they both work differently. _input() is called everytime there is an input while physics process checks for input (in my case) 60 frames per second. But is there still any benefit? 2 2 Jan. 27, 2025
  • Read this!!CelsUpon rereading this module, I am quite impressed that I have learned more than I initially expected. It has been more than enough to sharpen my skills. I am very glad that I joined this course, as it has provided me with valuable knowledge and growth. Now, I eagerly await the **M12** update, and when that happens, I won’t be able to contain my excitement! 1 0 Mar. 29, 2025
  • Node Access Logicchubby-frogI have a question about how the script for the weapon is able to access the node for the bullet. To my understanding, the function to shoot the bullet instantiates the scene, but adds the node to the chosen root, in which this example, is just a node2D room/level one hierarchy above (parent). This would make the the weapon and bullets scenes siblings? I know in the previous lessons there were different ways we needed to access nodes if they were not the children of the designated node, so why does it work to just in the weapon script that we can simply reference the properties of the bullet variable and reassign them the max bullet speed and range? My first thoughts would be that it had something to do with the exported reference of the scene, but I removed that and it still worked just fine. My best guess is that the reference and properties are accessed prior to the assignment of the bullet to its place on the node tree, but I am just not sure considered the code for add_child comes first. 2 0 Mar. 29, 2025
  • QuestionarjunI am struggling a lot with this so can I use the code reference to finish? It's also making me really angry and frustrated when I either can't focus when I'm reading the lesson or doing code I can't do. I am also on a tight deadline to make a game so if I don't understand or know how to do something, is it okay if I use the reference to copy it as long as I understand it by looking at the reference? 2 0 Mar. 21, 2025
  • Where can i find the complete tutorial for doing this?trained-bisonIve been triyng and i dont know how to do this 1 0 Mar. 19, 2025
  • Different solution for the random_angle challenge + questionsGoatzHey ! So here's my solution to the lesson. What do you guys think ? : ```gdscript extends Node2D @export var bullet_speed : float @export var bullet_max_range : float ##I added the bullet.tscn in the inspector @export var bullet_scene : PackedScene = null var random_angle := 10 * (PI/180) func _physics_process(delta: float) -> void: if Input.is_action_just_pressed("shoot"): shoot() func shoot(): var bullet : Bullet = bullet_scene.instantiate() get_tree().current_scene.add_child(bullet) bullet.global_position = global_position bullet.global_rotation = global_rotation bullet.global_rotation += randf_range(-random_angle, random_angle) ##If we didn't change the bullet_max_range and/or the bullet_speed values in the inspector ##It takes the bullet.tscn values by default if bullet_max_range and bullet_speed > 0.0 : bullet.speed = bullet_speed bullet.max_range = bullet_max_range ``` It's quite different from what you guys made which triggers a few questions in my brain : 1) I don't understand the use of the `@export_range` when declaring the `random_angle`, `max_range` and `max_bullet_speed` variables. I just got away with a regular float variables. Is it okay ? Also, where does the (PI / 12.0) come from ? I'm really curious on how you chose that particular value for the random_angle. ```gdscript @export_range(0.0, 360.0, 1.0, "radians_as_degrees") var random_angle := PI / 12.0 ``` 2) You added the result of the `randf_range` on top of the `bullet.rotation`. Was it wrong to add it on top of the `bullet.global_rotation` like I did ? I don't see the difference in this case as the bullet would be a child of the current scene's root node whose positions & rotation are 0 (...right ?). ```gdscript bullet.rotation += randf_range(-random_angle / 2.0, random_angle / 2.0) ``` 3) Also, why do we divide the `random_angle` by 2.0 in the randf_range ? Is it just to generate a lower value or is there some mathematical shenanigans that I don't understand ? Could we declare something like `var random_angle := PI /24.0` instead ? __________ Sorry for the long post. I really like this module so far. It's great, it's fun and I'm learning a lot ! Thank you so much for your hard work ! 2 0 Mar. 12, 2025
  • My weapon rotation still feels weird. blind-ibis```gdscript #Hello I'm trying to do the weapon position and rotation by myself, it is kinda working but it looks weird on diagonals. Is there a way to inherit the position using the parent node? I tried to create a variable for CharacterBody2D and didn't worked class_name Weapon extends Node2D @export var bullet_scene: PackedScene = null @export var speed : float = 1000 @export var max_range : float = 1500 const UP_RIGHT = Vector2.UP + Vector2.RIGHT const UP_LEFT = Vector2.UP + Vector2.LEFT const DOWN_RIGHT = Vector2.DOWN + Vector2.RIGHT const DOWN_LEFT = Vector2.DOWN + Vector2.LEFT func shoot_bullet() -> void: var bullet: Bullet = bullet_scene.instantiate() get_tree().current_scene.add_child(bullet) bullet.global_position = global_position bullet.global_rotation = global_rotation print("Bullet shot") func _physics_process(delta: float) -> void: var rotation_vector = Input.get_vector("Left", "Right", "Up", "Down") global_rotation = rotation_vector.angle() shoot() match rotation_vector: Vector2.RIGHT: position.x = 90 position.y = -10 Vector2.LEFT: position.x = -90 position.y = -10 Vector2.UP: position.x = 0 position.y = -90 Vector2.DOWN: position.x = 0 position.y = 90 UP_RIGHT: position.x = 90 position.y = -90 UP_LEFT: position.x = -90 position.y = -90 DOWN_RIGHT: position.x = 90 position.y = 90 DOWN_LEFT: position.x = -90 position.y = 90 func shoot(): if Input.is_action_just_pressed("Shoot"): shoot_bullet() ``` 3 0 Mar. 10, 2025
  • Same challenge explained twice ?WatchinofoyeAren't 2nd challenge's bonus and 3rd challenge actually the same challenge ? If so, why explain it twice ? 2 0 Feb. 03, 2025
  • My solution for random angle + dumb questionPurpleSunriseHi! My solution to random angle! This one was pretty fun! It's a bit different from the reference code but I didn't use hints. ```gdscript class_name Weapon extends Node2D @export var bullet_scene : PackedScene @export var max_range : float = 400.0 @export var max_bullet_speed : float = 600.0 #Is this how you convert degrees to radians...? var min_angle = -(10 * (PI/180)) var max_angle = (10 * (PI/180)) func _ready() -> void: randomize() func _physics_process(delta: float) -> void: if Input.is_action_just_pressed("shoot"): shoot() # I thought I'd try with the _input as well, it works but I guess it's not very functional. # If I have to set_physics_process(false) I'll also have to set_process_input(false) # while having everything inside the _physics_process() is better I guess? #func _input(event: InputEvent) -> void: #if event.is_action_pressed("shoot"): #shoot() func shoot(): var bullet : Bullet = bullet_scene.instantiate() bullet.global_position = global_position bullet.global_rotation = global_rotation bullet.speed = max_bullet_speed bullet.max_range = max_range bullet.rotate(randf_range(min_angle - rotation, max_angle - rotation)) get_tree().current_scene.add_child(bullet) ``` **Dumb question:** I don't like all the @tool stuff much, at the moment I feel it kind of complicates things for me to have functions in the script that are not really functional, as I am still learning and I see @tool as a secondary thing. Is it wrong to think that way and leave it out for the time being or should I make effort and start including that in my codes from now to be confident with it later on? Thank you! 3 0 Jan. 21, 2025
  • setting the bullet position after add_child() causes problemsDMK`new_bullet.global_position = global_position` `get_tree().current_scene.add_child(new_bullet)` This works, but `get_tree().current_scene.add_child(new_bullet)` `new_bullet.global_position = global_position` This causes a problem where you can see the bullet get spawned somewhere else around the player and then immediately jumps to the weapon's position. I know that theoretically the execution for both lines of code happen before the frame is rendered so this shouldn't be possible, which is why I'm very confused. Should I just set all the properties of the new node before add_child()? Is there a reason you add_child() first and then set the properties? 3 0 Jan. 14, 2025
  • About the Angle of the bullethumble-pelicanI have a question, why is it that when I add the function bullet.rotation += randf_range(-random_angle/2.0,random_angle/2.0), my bullets go in all directions, is that right? Because I watched the video of the last challenge example in line 10 0 Jan. 03, 2025
  • A few things here that I don't quite get.PJ1. Why isn’t "random_angle" actually random and instead has a fixed value here? 2. What does "radians_as_degrees" mean? 3. Why are we modifying the "global_rotation" property, but then only editing "rotation" on line 33? 4. When using `randf_range`, why do we divide "random_angle" by 2.0? Wouldn’t it have been more convenient to set the correct property value on line 6 instead? 1 0 Jan. 03, 2025
  • When to call add_child, before defining properties or after? Lucas PscheidtI had this code for the shoot function before reading the reference: ```gdscript var bullet_instance : Bullet = bullet.instantiate() bullet_instance.global_position = global_position bullet_instance.rotation = rotation bullet_instance.max_range = bullet_max_range bullet_instance.speed = bullet_speed timer_cooldown.start(cooldown_seconds) get_tree().current_scene.add_child(bullet_instance) ``` I was wondering, is there any problem with calling `add_child()` after defining the properties? One thing I noticed was that if I called this line before setting the properties, my bullets would instantly call the `destroy` function upon spawning. This happened because, in their `_ready()` function, I was setting `initial_position = global_position` to calculate `max_range`. To fix that, I used `call_deferred()` to delay the `initial_position` assignment, and it worked. However, if I call `add_child()` after setting the bullet's properties, it also works without needing `call_deferred()`. Are there any drawbacks to this method? 3 0 Jan. 02, 2025
  • AudioStreamChuckAm I missing something or is there no code for making the firing sound in the reference code? 1 0 Jan. 01, 2025
  • Accidentely forgot to remove @tool after testing the warning stuff in bullet.gd & now the editor auto close itself even on a restart◆ LPIt probably happened because I removed the code for Engine.is_editor_hint() condition. I know I can change the script outside the Godot to fix this but I still find it a little amusing. The bullet moves & then closes the editor after reaching it's destination. 1 0 Dec. 17, 2024
  • Radians vs DegreesPaulI'm having a bit of a tangle getting my head around Radians. I understand how they are different to degrees, but my brain hasn't got used to calculating/visualising them. For instance, in final challenge, I did: ```gdscript ##A value of 0 is perfect accuracy. Higher values increase spread. @export_range(0, 20) var weapon_spread := 5 func shoot() -> void: ... var spread_modifier := randf_range(0 - weapon_spread, weapon_spread) bullet.global_rotation_degrees = global_rotation_degrees + spread_modifier ``` This makes sense in my brain, and it works here. I know it's going to add a few degrees either side to the angle of the shot. But I fear 'cheating' with the `rotation_degrees` property now might cause me some problems in the future? Should I try to stick with radians or is there a time and place to use either. 8 0 Dec. 05, 2024
  • Why do you add @tool in the Code Reference?MuryanIt feels like it’s unnecessary. Without @tool, it seems the entire code still works fine. 3 0 Nov. 24, 2024
Site is in BETA!found a bug?