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.

  • Little note on reference code:PurpleHuesI noticed that when using % on DetectionArea I get an error "Invalid access to property or key 'body_entered' on a base object or type 'null_instance'. When I replace % with $ it works fine, but what does the error mean? 3 0 Feb. 20, 2025
  • My Sword mob Code!pikminfan71Hope it's ok! ```gdscript class_name Mob extends CharacterBody2D @onready var _area_2d: Area2D = %Area2D @onready var _player: Player = null @export_range(200.0, 2000.0, 1) var speed: float = 800.0 func _physics_process(delta: float) -> void: if _player == null: var direction : Vector2 = Vector2.ZERO velocity = velocity.move_toward(direction, speed / 2.0 * delta) elif _player: var direction = global_position.direction_to(_player.global_position) var distance = global_position.distance_to(_player.global_position) velocity = velocity.move_toward(direction * distance, speed * delta) move_and_slide() func _ready() -> void: _area_2d.body_entered.connect(func(body: Node) -> void: if body is Player: _player = body ) _area_2d.body_exited.connect(func(body: Node) -> void: if body is Player: _player = null ) ``` 5 0 Feb. 04, 2025
  • Do we really need "if player = null"?oliver_gzzHey there, when I was comparing the code that I made based on past lessons, I ended up with this in my func `_physics_process(delta)` **code below** my question is, do we really need the line: `if _player == null:` ` velocity = velocity.move_toward(Vector2.ZERO, acceleration * delta)` **this is the code I have:** ```gdscript if _player != null: var direction := global_position.direction_to(_player.global_position) var distance := global_position.distance_to(_player.global_position) var speed := max_speed if distance > 100 else max_speed / 200 var desired_velocity := direction * speed velocity = velocity.move_toward(desired_velocity, acceleration * delta) move_and_slide() ``` 4 0 Jan. 30, 2025
  • Question about global_positionkazaHello! I'm loving this course! But i get a question: I achieve the final result of this chapter and i forgot and i used position instead global_position. Do you can you explain me why position (instead global_position) can lead to unexpected results or bugs? 2 0 Jan. 29, 2025
  • My solutionPurpleSunriseHello! My code was very similar to the reference! I didn't implement the feature that the swords slows down when it gets closer to the player. Do I have to modify the code to adapt it to the reference or is it ok if it's a bit different? ```gdscript class_name Mob extends CharacterBody @onready var detect_area: Area2D = %DetectArea @export var max_speed : float = 200.0 @export var acceleration : float = 1000.0 @export var deceleration : float = 400.0 var _player : Player = null func _ready() -> void: detect_area.body_entered.connect(func(body : Node)->void: if body is Player: _player = body) detect_area.body_exited.connect(func(body : Node)->void: if body is Player: _player = null) func _physics_process(delta: float) -> void: if _player != null: var direction = global_position.direction_to(_player.global_position) var desired_velocity : Vector2 = max_speed * direction velocity = velocity.move_toward(desired_velocity, acceleration * delta) else: velocity = velocity.move_toward(Vector2.ZERO, deceleration * delta) move_and_slide() ``` 1 0 Jan. 23, 2025
  • why i am getting this error?AngryCapybaraHello! Could you please help me? I am defining the `player` variable exactly like this: `var _player: Player = null` However, I keep getting the following error: `Parse Error: Could not find type "Player" in the current scope.` What am I missing? 3 0 Jan. 09, 2025
  • Motion Mode: Grounded / FloatingRuben TeijeiroThere is some error when explaining the Motion Mode property of the CharacterBody2D. The initial explanation in the Challenge is: > Make sure to set the  `CharacterBody2D` node's *Motion Mode* property to *Grounded*, otherwise, the mob will stick to the player when colliding with them. But in the Questions section it's explained like this: > The  `CharacterBody2D` node has a property called *Motion Mode*. By default, it's set to *Grounded*, which is designed for games with a side view and tries to detect slopes, walls, and ceilings. You need to change it to *Floating* for top-down games. I assume the second is the correct one, right? 1 0 Dec. 06, 2024
  • DecelerationMarcJLooking at the version of the code reference I don't see the velocity ever decelerating or reset when the player exits the mob detection range. So it seems to me that the acceleration will only occur the first time the player enters the mob range and then the next time the player enters into the detection range the mob moves at max speed or am I missing something? 1 0 Nov. 19, 2024
  • Rotation for the weaponiguessfiveI finding it difficult to identify where the rotation is set for the weapon to pass to the bullet. Is the rotation for the weapon set based on the direction the player is facing or the angle of the mouse's global position if using mouse to shoot the bullet. Or either is fine. 2 0 Nov. 18, 2024
Site is in BETA!found a bug?