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 enemy's weapon is firing, but nothing is coming outfaint-gerbilI've been at this for a while trying to debug, using temporary print calls, and double checking all of my collisions in case the bullet is just getting instantly destroyed by colliding with the mob. I created a separate bullet script as mentioned in another post. I even reverted to changing all of my code to the code listed in the solutions here, but STILL my enemy bullets won't come out at the player. Could someone please have a look and help me understand what it is I'm glossing over that's causing my enemy to fire but for no bullet to come out? [https://drive.google.com/drive/folders/11FT1Vbpyr5SccQRMe8UaOtbykL-ft1Jc?usp=sharing](https://drive.google.com/drive/folders/11FT1Vbpyr5SccQRMe8UaOtbykL-ft1Jc?usp=sharing) Not sure if there's a better way to share, but I figure the code alone may not be enough. 3 0 May. 07, 2025
  • Mob hits itselfilliterate-spiderHi Ive trying to figure out why my mob keeps shooting itself. I double checked and tried the reference setter and condition of mob and player but couldnt figure it out. Heres my link to my project if you wanna take a look [https://drive.google.com/file/d/12ufmak_TmyuHQJZyH4SpcOMjibITifYy/view?usp=sharing](https://drive.google.com/file/d/12ufmak_TmyuHQJZyH4SpcOMjibITifYy/view?usp=sharing) The following scenes are the equivalents to my project to the solutions project. mob_follow = mob fireball_mob = bullet player = player fireshot = mob_weapon mob_flying_turret = mob_shield Thanks in advance! 6 0 Apr. 26, 2025
  • Question about classes and extending resourcesSootyWhen following along with this lesson, rather than coding the Shooting Mob from scratch I extended the Mob class. I have noticed a couple of times now, If i change say the ready function , it changes the entire ready function. When you want to make changes, say in this instance adding a new shoot_timer.timeout.connect(weapon._shoot) , do I really have to go back to the parent script and copy paste the original code again into the new extended script? Is there any way to add a single extra line if the rest of the ready or physics process function remains the same? In the following code, I only added 5 lines to update the mob to the shooting mob, the 2 variables at the top the shoot_timer connection weapon.look_at(vector2.Zero) in the body exited function, not sure if this is necessary and in the physics process the weapon.look_at(_*player.global_*position) ```gdscript extends Mob @onready var shoot_timer: Timer = %ShootTimer @onready var weapon: Weapon_Mob = %Weapon func _ready() -> void: shoot_timer.timeout.connect(weapon._shoot) mob_detector.body_entered.connect(func(body: Node)-> void: if body is Player: _player = body shoot_timer.start() ) mob_detector.body_exited.connect(func(body: Node)-> void: if body is Player: _player = null shoot_timer.stop() weapon.look_at(Vector2.ZERO) ) hit_box.body_entered.connect(_hitbox_entered) hit_box.body_exited.connect(_hitbox_exited) hit_timer.timeout.connect(func() -> void: if contact == true: _player.health -= damage ) func _physics_process(delta: float) -> void: if _player == null: velocity = velocity.move_toward(Vector2.ZERO, acceleration * delta) if _player != null: var direction = global_position.direction_to(_player.global_position) var distance = global_position.distance_to(_player.global_position) #only need distance for the smoothing algo var speed = max_speed if distance > 100 else max_speed * distance / 100 var desired_velocity = direction * speed velocity = velocity.move_toward(desired_velocity, acceleration * delta) weapon.look_at(_player.global_position) move_and_slide() ``` 5 0 Mar. 25, 2025
  • inheritance on mob who shootsSandra MoenI used inheritance on the mob that shoots, and solved the shoot-timer a bit differently. It works. ```gdscript class_name MobShooter extends Mob @onready var _shoot_timer: Timer = %ShootTimer @onready var _weapon_manual: WeaponManual = %WeaponManual func _ready() -> void: # super() doesn't work(?) initialize() _shoot_timer.timeout.connect(_weapon_manual._shoot) func _on_detection_entered(body: Node) -> void: # super() doesn't work(?) if body is Player: _shoot_timer.start(0.0) # documentation doesn't mention if stop() also resets to 0.0 _player = body func _on_detection_exited(body: Node) -> void: # super() doesn't work(?) if body is Player: _shoot_timer.stop() _player = null ``` I had to move everything in `Mob`'s `_ready()` to it's own public `initialize()` function because `super()` didn't work. Why does `super()` not work on `_ready()`? and my detection enter/exit functions as well? 1 0 Mar. 06, 2025
  • My mob don't want to shoot mePixAngelI don't understand why my mob don't want to shoot the player. I've been looking for this issue for two hours now... and nothing I share all my scripts, if anyone has an idea of what I'm doing wrong : mob_2.gd: ```gdscript class_name Mob2 extends Mob @onready var area_2d: Area2D = %Area2D @onready var weapon_2: AutoWeapon = $Marker2D/Weapon2 @onready var _cool_down_timer: Timer = %CoolDownTimer func _ready() -> void: super() _cool_down_timer.wait_time = 1.0 _cool_down_timer.timeout.connect(func () -> void: if _player != null: weapon_2.shoot() ) _cool_down_timer.start() func _physics_process(delta: float) -> void: var desired_velocity = Vector2.ZERO if _player != null: var direction = global_position.direction_to(_player.global_position) var distance = global_position.distance_to(_player.global_position) desired_velocity = direction * max_speed weapon_2.look_at(_player.global_position) velocity = velocity.move_toward(desired_velocity, acceleration * delta) move_and_slide() ``` bullet_2.gd: ```gdscript class_name Bullet_2 extends Area2D @onready var _destroy_sound: AudioStreamPlayer = %AudioStreamPlayer @export var max_speed := 950.0 @export var max_range := 1200.0 @export var damage := 1 @export var target_player : bool : set = set_target_player var traveled_distance := 0.0 func _ready() -> void: body_entered.connect(func (body : Node) -> void: if body is Mob2 or body is Player: body.health -= damage _destroy() ) set_target_player(target_player) func _physics_process(delta: float) -> void: var direction = Vector2.RIGHT.rotated(rotation) var velocity = direction * max_speed position += velocity * delta traveled_distance += max_speed * delta if traveled_distance > max_range: _destroy() func _destroy() -> void: set_physics_process(false) queue_free() func _on_body_entered(body : Node): if body is Player: body.health -= damage _destroy() func set_target_player(value : bool) -> void: target_player = value const PLAYER_PHYSICS_LAYER = 1 const MOB_PHYSICS_LAYER = 3 set_collision_layer_value(MOB_PHYSICS_LAYER, not target_player) set_collision_layer_value(PLAYER_PHYSICS_LAYER, target_player) ``` weapon2.gd: ```gdscript class_name AutoWeapon extends Weapon @export var bullet_2 : PackedScene = null @onready var _cool_down_timer: Timer = %CoolDownTimer func _physics_process(delta: float) -> void: return func shoot() -> void: var new_bullet : Bullet_2 = bullet_2.instantiate() get_tree().current_scene.add_child(new_bullet) new_bullet.target_player = true new_bullet.global_position = global_position new_bullet.global_rotation = global_rotation new_bullet.rotation += randf_range(-PI / 30.0, PI / 30.0) ``` 4 0 Jan. 23, 2025
Site is in BETA!found a bug?