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.
Making collision shape child of sprite for rotationprivate-dragonflyIf we had a non-uniform collision shape (rectangular for example), would moving the collision shape inside of the sprite 2D so that it rotates with the sprite be appropriate?
Or would it be better in this case to keep them sibling nodes and rotate the collision shape on another line312Mar. 02, 2024
Using Unique Name instead of get_node() ?RaspiWould it be beneficial in any way to use a UniqueName instead of the get_node() way? Will it be "better" in terms of performance in the long run? (for big things, not small projects like this)
Or alternatively , storing the node in a onReady function?
I'd imagine for tutorial purposes and to keep things focused in the healthbar rotation etc. makes more sense to directly use the get_node().
Thanks and keep it up!37Feb. 21, 2024
Whether the health progress bar can be modularizedpast-muleCan I create health in a new node and add it to the Ship? So I can reuse the health progress bar node in different monsters, characters, items without creating a health progress bar each time, is this reasonable?42Feb. 20, 2024
Attaching a script to the Sprite2D for rotation.Tarek_MouradIs it possible to attach a script to the sprite and manipulate the rotation at the process function of the sprite? If so, isn't that more organized to do, having all the functions related to the sprite at the sprite node itself or it is better for readability to have all that at the same script?11Apr. 25, 2024
Unable to resize the healthbarmeasly-jayI try to resize using the SELECT and it won't allow me to narrow the health bar. What step did I miss?10Dec. 14, 2024
Different approach to prevent the health bar from rotatingMoerklerI tried to find a different approach to prevent the health bar from rotating, because I thought, if the collision shape was not a circle, you would want it to also rotate, which it does not in the current script.
You could probably just code it like this:
```gdscript
if velocity.length() > 0.0:
var angle := velocity.angle()
get_node("Sprite2D").rotation = angle
get_node("CollisionShape2D").rotation = angle
```
But I thought it would be better to set the rotation of the 'exceptional cases' (here the `HealthBar` or `UI` node) to zero instead of setting all the other rotations to the desired angle.
My first approach
```gdscript
if velocity.length() > 0.0:
rotation = velocity.angle()
get_node("UI").rotation = 0
```
ended up making no difference, because the rotation of the `UI` node is just added to its parent's rotation instead of overwriting it.
I browsed through the Q&A section and found a hint about the property *Top Level*. Trying to use this one with the value `true` for the `UI` node, I ended up with a health bar that did not move, because it (of course) then also ignores the position of its parent.
Is the *Top Level* property a valid approach to achive this task and if so, how would you do it? I figured that I could use the property and then set the position of the UI according to its parent in the `_process` function, but that seems not very elegant either.
```gdscript
if velocity.length() > 0.0:
rotation = velocity.angle()
get_node("UI").position = position
```
Is there a way to prevent only some of the transform properties to depend on the the parent node or what would be a nice way to archive the task?10Dec. 13, 2024
I don't get itxealThe script we edit is this
if velocity.length() > 0.0:
#rotation = velocity.angle()
get_node('Sprite2D').rotation = velocity.angle()
wasn't the "rotation = velocity.angle()" bit included so that the ship would remain pointing in the last direction pressed? now It's removed and the ship still behaves the same way? how come?
Now though we've added a new line to stop the bar from rotating?
buuut... doesn't the "get_node("sprite2d").rotation =... tell the progress par to rotate the where ever the key is pressed just like that ship was? Isn't that what velocity.angle() at the end of the line tells it to do once the velocity.length is greater than 0?
head scratcher here...20Dec. 09, 2024
regarding healthbar and rotationrifqilubis ```javascript
if velocity.length() > 0.0:
```
if velocity change to direction, desired_velocity, max_speed. it doesn't matter right??. cause the value will be always more than 1??
and it always working(?)
10Dec. 08, 2024
The impact of key detection on ProgressBar displayBruceI've created a progress bar for the boost of the spaceship, which is used to display the duration and the charging time.
However, I've found a problem. If I keep pressing the boost key, the progress of the progress bar will get stuck and won't be able to display dynamically.
Below is my spaceship code. I'm asking for guidance.
```javascript
@onready var timer := $Timer
@onready var boost_bar := $UI/BoostBar
@onready var ship := $ShipSprite2D
var velocity := Vector2(0, 0)
var speed := 0.0
var normal_speed := 600.0
var max_speed := 1600.0
var is_boosting := false
var steering_factor := 15.0
func _ready() -> void:
speed = normal_speed
timer.timeout.connect(_on_timeout)
boost_bar.visible = false
func _process(delta: float) -> void:
var direction := Vector2(0, 0)
direction.x = Input.get_axis("move_left", "move_right")
direction.y = Input.get_axis("move_up", "move_down")
var desired_velocity := direction.normalized() * speed
var steering := desired_velocity - velocity
velocity += steering * steering_factor * delta
position += velocity * delta
if direction.length() > 0:
ship.rotation = direction.angle()
if Input.is_action_pressed("boost"):
if is_boosting:
return
speed = max_speed
timer.wait_time = 1.0
boost_bar.visible = true
boost_bar.max_value = 1.0
timer.start()
is_boosting = true
if boost_bar.visible:
if boost_bar.max_value == 1.0:
boost_bar.value = timer.time_left
elif boost_bar.max_value == 2.0:
boost_bar.value = 2.0 - timer.time_left
func _on_timeout() -> void:
if speed > normal_speed:
speed = normal_speed
timer.wait_time = 2.0
boost_bar.max_value = 2.0
timer.start()
else :
is_boosting = false
boost_bar.visible = false
```50Dec. 04, 2024
My Inspector didn't show the StyleBoxFlat propertiesfront-railWhen I got to styles and set it to StyleBoxFlat, it ticked the "fill" box, but it didn't show any additional settings to change colors etc. Did I miss a step or something? 20Oct. 31, 2024
Suggestion: Allow mouse wheel to change Inspector valuesbunshinesoyI see that you can use the up and down arrow keys to change values in the inspector. It'd be nice if you can use mouse wheel scrolling to also change the values. I'm used to this behavior from photoshop/lightroom and feels like it would naturally fit in here.10Oct. 20, 2024
What would be a use case for "StyleBoxLine"?stark-echidnaIn the lesson it is said that StyleBoxLine is rarely used. But what would be an actual use case?10Sep. 17, 2024
Nodes Control and more HazlarHello everyone,
In the node tree, node2D and Control appear as a spacer indicating a general category, are they used in usage as a visual use of readability with the power to modify all of its children that share the same properties. I duplicated the HealthBar and then modified the color via the Control node and this has indeed modified the colors of the two bars at the same time.
To summarize:
Are the Node2D or control nodes nodes that express a general category? Are they used mainly as a visual spacer in our dock so that it is visually more structured?
For Area2D I see that its general category is CollisonObject2D, should we have defined it upstream before our Area2D?
Thanks in advance30Jun. 23, 2024
Sprite rotation and lerp_anglep_dev_In a previous lesson, I had used the code to lerp the angle of the ship.
When seeking to avoid the rotation of the health bar, I tried the following code in the ship script:
```gdscript
func _process(delta: float) -> void:
#...
var target_rotation = velocity.angle()
get_node("Sprite2D").rotation = lerp_angle(rotation, target_rotation, delta * 7)
```
But the ship just starts rotating very slightly, and doesn't complete the movement. Where could the problem be?20Jun. 22, 2024
UI Control node as parent?machinemanI noticed we created Control node to serve as the parent of the progress bar... but could we just have the progress bar node? What is the reason for creating the parent?10May. 05, 2024
No slider available with progress bar's value property?leafNothing major here, but I was looking all over the place for the slider mentioned in the lesson text for the `value` property, either I have missed this altogether, or it does not exist (anymore?). Caused a slight of confusion for me, will likely cause confusion for other students in the future as well!10Apr. 21, 2024
Small improvement to the lessonAlainYou should take the opportunity when talking about this line:
```gdscript
get_node("Sprite2D").rotation = velocity.angle()
```
To explain it could be replaced with
```gdscript
$Sprite2D.rotation = velocity.angle()
```
As we see a lot of usage of the ` operator on the web and it is not obvious how to use it at first.10Apr. 05, 2024
Do you have any topics on theming?iadgybf8iawgFor example, dark/light ui mode, consistant UI theme for different ui elements, reusable UI component etc.10Mar. 14, 2024
Show pixels info for position and sizeGreg GGTIn the "Move and resize the health bar" part:
In the second GIF, you have information on the position and size of the pixels that appear when the progress bar is resized and moved.
How can I see this information too?
Thx :)50Mar. 02, 2024
Theme override is missing?old-fashioned-elephantThis isn't really related to the course but I am using the version of Godot that came with the lesson files for this module and I do not have "theme overrides" in my Control settings. The last item in that section is"Theme" could I be missing something?60Feb. 28, 2024
UI placementTrifidehi there, i was playing a little with the UI on later lessons and i saw that it goes under the collectibles, why is that and should'nt it be the other way arround?20Feb. 23, 2024
Typo in "What's a hex value?"AnanasIn "What's a hex value?" it states that "So, in hex, nine is followed by A, B, C, D, E, and F (F corresponds to the number 16)." This is incorrect, as 0xF corresponds to 15, so 0x10 would correspond to 16.10Feb. 21, 2024
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.