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.

  • My Solution for the `move_and_slide` challengeAbdul Hannan AhmedHi! Here's my solution for the `move_and_slide` challenge. I can't believe it actually works in the actual practice too! ```gdscript extends CharacterBody2D @onready var sprite_2d: Sprite2D = %Sprite2D @onready var collision_shape_2d = %CollisionShape2D @onready var cursor: Area2D = %Cursor var max_speed := 600.0 var distance := 0.0 var direction := Vector2.ZERO var duration := 0.0 var target_vector := Vector2.ZERO var tween: Tween func _physics_process(delta: float) -> void: if target_vector != Vector2.ZERO: var desired_velocity = global_position.direction_to(target_vector) velocity = velocity.move_toward(desired_velocity, max_speed * delta) move_and_slide() func walk_to(destination_global_position: Vector2) -> void: # Calculate the distance and direction to the destination. distance = global_position.distance_to(destination_global_position) direction = global_position.direction_to(destination_global_position) # Make sure to calculate the duration based on the distance to the target. duration = distance / max_speed # This code ensures that if the player clicks quickly, # the previous "walk to" animation is cancelled and cannot conflict # with the new destination. if tween != null: tween.kill() tween = create_tween() tween.tween_property(self, "global_position", destination_global_position, duration) rotation = direction.orthogonal().angle() func _input(event: InputEvent) -> void: if event is InputEventMouseButton \ and event.button_index == MOUSE_BUTTON_LEFT \ and event.is_pressed() == false: #walk_to(cursor.global_position) target_vector = cursor.global_position ``` Thank you GDQuest for this course. You're doing a great job and I feel like I am becoming more of an independent developer myself. Totally more than worth the money than I paid for! 1 1 Nov. 12, 2024
  • My solution to the move_and_slide() challengePJ```gdscript extends CharacterBody2D @onready var sprite_2d: Sprite2D = %Sprite2D @onready var collision_shape_2d = %CollisionShape2D @onready var cursor: Area2D = %Cursor var max_speed := 600.0 var target := global_position func _physics_process(_delta: float) -> void: var direction := self.global_position.direction_to(target) var distance := self.global_position.distance_to(target) if distance > 6: rotation = direction.orthogonal().angle() velocity = direction * max_speed else: velocity = Vector2.ZERO print("distance: ", distance) move_and_slide() func _input(event: InputEvent) -> void: if event is InputEventMouseButton \ and event.button_index == MOUSE_BUTTON_LEFT \ and event.is_pressed() == false: target = cursor.global_position ``` I'm not a fan of the hardcoded `if distance > 6` part, but without it, the ship glitches in a loop. Do you have any ideas for a better solution? 2 1 Nov. 10, 2024
  • move_and_slide() challenge and questionsPurpleSunriseHello, here's my solution to the `move_and_slide()` challenge. It works pretty well but I have a couple of questions regarding this challenge and something else. First the code: ```gdscript extends CharacterBody2D @onready var sprite_2d: Sprite2D = %Sprite2D @onready var collision_shape_2d = %CollisionShape2D @onready var cursor: Area2D = %Cursor var max_speed := 600.0 var target := global_position var direction := global_position.direction_to(target) func _physics_process(delta: float) -> void: # I had to put a limit because if I didn't the direction was going crazy # once reached the target. # Does anyone know why? Is there an error in my code? if global_position.distance_to(target)< 2.0: velocity = Vector2.ZERO else: direction = global_position.direction_to(target) velocity = direction * max_speed * delta position += velocity move_and_slide() if direction.length() > 0.0: rotation = direction.orthogonal().angle() func _input(event: InputEvent) -> void: if event is InputEventMouseButton \ and event.button_index == MOUSE_BUTTON_LEFT \ and event.is_pressed() == false: target = cursor.global_position ``` Question (which is also in the comments). Without that threshold the direction was going crazy after reaching the target. It was varying between -0.00051 and 0.01512 for example. Is it some logic limitation or calculation of godot? **ENUM:** I've seen enum a couple of times in the module but I don't have any idea of what it is. Is it going to be explained in the next lessons? Thank you! 3 0 Dec. 08, 2024
  • Question: Accessing the walk_to function from the game.gdoliver_gzzHey there, this might be super obvious, but how are we able to access the `walk_to` function we defined in the **runner.gd** in the **game.gd.** Is it because, we're defining the **`var runner := body as Runner` ?** and by doing this, we can access all functions that the Runner type has everywhere in the game? thanks! 2 0 Nov. 26, 2024
  • move_and_slide() ChallengePixAngelHellow there, Here's my solution I find very simple compare to others. Hope i'm not wrong: ```gdscript extends CharacterBody2D @onready var sprite_2d: Sprite2D = %Sprite2D @onready var collision_shape_2d = %CollisionShape2D @onready var cursor: Area2D = %Cursor var max_speed := 600.0 var target := global_position var direction := Vector2.ZERO func _physics_process(_delta: float) -> void: direction = global_position.direction_to(cursor.global_position) velocity = direction * max_speed rotation = velocity.orthogonal().angle() move_and_slide() func _input(event: InputEvent) -> void: if event is InputEventMouseButton \ and event.button_index == MOUSE_BUTTON_LEFT \ and event.is_pressed() == false: target = cursor.global_position ``` Then, I want to report some problems: Since we have configured Runner position in order to overlap the FinishLine, Y sort doesn't work well on simple obstacles. Now Runner is always on top, even when it is positionned on the top of the object whereas we want it behind. And my confettis don't pop when Runner reach the line. 4 0 Nov. 25, 2024
  • My runner dissapear when it cross the finish line00ALBI am struggling to understand why the runner is dissapearing when i am crossing the finish line. I can see the begining of the tween, but it seems it goes somewhere behind an invisible layout, and... confetti!! I check with a print to see where it goes (destination_position). but it's the good position to target! Do you have an idea of my issue? 3 0 Nov. 21, 2024
  • Challenge: Using move_and_slide() instead of Tween!AJ StudiosAt first my mind went blanc and had no idea what to do but I understand that I just have to use move_and_slide() instead of a Tween. I then saw a couple of solutions from other students here in the comments. The one provided by @Abdul Hannan Ahmed was interesting but I don't understand why he still uses `var tween : Tween` and `tween = create_tween()` in the `walk_to()` function. Wasn't the whole point of this challenge to use `move_and_slide()` instead of Tween? So I went ahead and duplicated the practice scene in a different directory and added a new script to the MouseShip node but the ship doesn't move when I click. Here's the folder: [https://drive.google.com/drive/folders/1VGFxXfgbWZSu9Ht55M39_B99gyb1tzgl?usp=sharing](https://drive.google.com/drive/folders/1VGFxXfgbWZSu9Ht55M39_B99gyb1tzgl?usp=sharing) I want to provide some feedback as a student. In my case since I'm learning to code as I go with this course, the most challenging thing for me is understanding how to compose the syntax. Just like learning let's say... Japanese, I have to learn the alphabet, then some words, then how to write a sentence in a way that makes sense, and eventually a paragraph. With GD Script, since there has been so many new functions and different syntax introduced so far, when I'm faced with a challenge my head goes blanc and I don't know what to do because I forget how to write some of the syntax and where it goes. Do you guys have any advise on what to do in my case so that I can improve my coding skills? I know the obvious answer to that is practice, I just don't know if it would be better to do that now or wait until I finish the course and then start practicing with little experiment projects on my own. 6 0 Nov. 20, 2024
  • About tweeting a safe path for the runner!AJ StudiosOn this lesson it says: `The main limitation of this approach is that, because we don't use the move and slide function when we tween the character, we are not handling collisions. So you have to be careful that the location you are tweeting to is safe for the character to reach. In this case, we know the finish line is safe, so we can use a tween.` I was just wondering if there is another method like path finding for the runner to follow (since we don't use move_and_slide() to handle collisions) in case there is hazards or obstacles like walls in the way. 7 0 Nov. 20, 2024
  • Trying out the walk_to()PJI’m having a bit of trouble understanding why, when I try out the `walk_to()` function in the `_ready()` function of `game.gd`, the character doesn’t play the `WALK` animation and instead just slides with the `IDLE` animation. However, when I continue with the rest of the lesson, everything works as expected. Could you help me understand why this happens?" `extends Node2D` `@onready var _finish_line: FinishLine = %FinishLine` `@onready var runner: Runner = $Runner` `func _ready() -> void:` `runner.walk_to(Vector2(12, 24))` 3 0 Nov. 09, 2024
  • Find out the direction of the player's runningram876Hello! And how to take into account which direction the character is running in, so that he can finish only if he runs a circle in the right direction? Otherwise, you can just run straight to the finish line from the start. So far, the idea has come to my mind that it is possible to arrange the Area2D nodes along the way and check for a collision. If they are small, the engine may not notice the intersection, and if you make them large, then, in my opinion, it will be problematic to find out which side of the node the player left (this is necessary in order to indicate to the player that he is not moving in the right direction). But even if you keep track in this way, you will need to manually put each node, number them. And if the path is long and then I decide to redo the path, I will either have to put all these nodes down again, or delete unnecessary ones or move existing ones. This method does not seem right to me. 2 0 Nov. 04, 2024
  • Challenge: using move_and_slide()Sandra MoenI was able to complete the challenge using this: ```gdscript func _physics_process(delta: float) -> void: var distance_to_target = global_position.distance_to(target) if distance_to_target > 0.0: var direction = (target - global_position).normalized() velocity = direction * distance_to_target else: velocity = Vector2.ZERO move_and_slide() ``` ```gdscript func walk_to(destination_global_position: Vector2) -> void: ... target = destination_global_position ``` The movement 'lerp', is fast in the beginning, and goes slower and slower, like a `CIRC EASE_OUT`. Not sure how I'd get different 'lerp's... 1 0 Oct. 15, 2024
  • My fix for the Runner still drawing behind the finish linejuthrbogMaking a standalone post for visibility. I originally just commented on the "Runner Still Shows up behind finish line" post below. Can't say for sure this is the right answer to the issue, but the Runner was still drawing behind the finish line even after I updated the Runner's pivot point. I ended up resetting the Runner's pivot point back to what it was and then set the Z Index of the FinishLine scene instance in the Game scene to -1 (the same Z Index set for the CircuitBackground Sprite2D node). Doing that allowed the Runner scene to draw on top of the finish line as shown in this lesson. 3 0 Oct. 14, 2024
  • Runner Still Shows up behind finish linepikminfan71Hi guys how are you? this is the project file you asked me to send you on discord regarding the problem, Thank you in advance! [https://we.tl/t-77SCIL27DK](https://we.tl/t-77SCIL27DK) 5 0 Oct. 14, 2024
  • confetti didn't popMuryanI noticed that when the character reached the middle of the finish line, the confetti didn't pop. The GPU particle system is running, but it's empty. [https://imgur.com/qs4uxLW](https://imgur.com/qs4uxLW) [https://imgur.com/ERyldRM](https://imgur.com/ERyldRM) I also tried the solution version, but it didn't work either. Here's the video I recorded. [https://youtu.be/rPT8DdBs4SI](https://youtu.be/rPT8DdBs4SI) How can I fix this? 5 0 Oct. 04, 2024
  • if body is not Runner ErrorRossI am getting an error which I am struggling to clear. In the section where we are connecting the signal from the player entering the finish line area.  At line 7 in game.gd ```gdscript if body is not Runner: ``` shows the error `Line 7:Expected type specifier after "is".` `Line 7:Expected "in" after "not" in content-test operator.`  I have named the runner class by typing ```gdscript class_name Runner ``` at the top of the runner.gd script. I have tried to reload the project as well as restarting the project but this didn't work. Another strange thing that is happening, is that I can’t add references to other nodes in the game.gd script for example when we click, drag then press ctrl to quickly add a @onready var.  When I try and do this within the game.gd I get a little popup at the bottom right of the screen that says `“Can’t drop nodes because script ‘game.gd’ does not inherit node"`. Everything else in the game.gd script is unaltered i.e. it still has extend Node2D at the top of the script. I don’t know if this is related to the first issue. Thanks in advance for any help you can offer in helping me understand the issue. 3 0 Oct. 03, 2024
Site is in BETA!found a bug?