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 0 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? 1 0 Nov. 10, 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) 2 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? 3 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. 2 0 Oct. 03, 2024
Site is in BETA!found a bug?