Godot version 3.6
I followed the book exactly as it says in chapter 5 space shooter, but the asteroid will not destroy in the game I’m on page 86 please help
Godot version 3.6
I followed the book exactly as it says in chapter 5 space shooter, but the asteroid will not destroy in the game I’m on page 86 please help
I do not have this book, can you paste more about your game project? Maybe the projectile and asteroid script?
sure here is the asteroid script
extends Area2D
var explosion_scene = preload(“res://scenes/explosion.tscn”)
var move_speed = 100.0
var score_emitted = false
signal score
func _process(delta):
position -= Vector2(move_speed * delta, 0.0)
if position.x <= -100:
queue_free()
func _on_asteroid_area_entered(area):
if area.is_in_group(“shot.tscn”) or area.is_in_group(“Player.tscn”):
if not score_emitted:
score_emitted = true
emit_signal(“score”)
queue_free()
var stage_node = get_parent()
var explosion_instance = explosion_scene.instance()
explosion_instance.position = position
stage_node.add_child(explosion_instance)
and here is the projectile script
extends Area2D
const SCREEN_WIDTH = 320
const MOVE_SPEED = 500.0
func _process(delta):
position += Vector2(MOVE_SPEED * delta, 0.0)
if position.x >= SCREEN_WIDTH + 8:
queue_free()
Looks good, are your signals connected? Could I see a screenshot of the scene tree?
sorry i have a multi monitor setup
It looks like your asteroid has a signal, your function name is _on_asteroid_area_entered
which might be connected to something else? Did you intentionally add asertoid
to the middle of the function name?
On windows you can press shift+windows+s to screenshot a selected rectangle, then paste it into the forums.
i am learning from a book and it was written like that in the book so yes
where do you see asertoid that may be my problem
Your asteroid Area2d has the signal connection icon, but the default function name would be _on_area_entered
if it was connected to it’s own script, that’s why I think it could be connected to another script/node. But you can change the function name
thanks for that tip on syntax but even after i fixed that still no change it doesn’t disappear when hit or sets off the explosion
I am not sure anything was to be fixed, double check your signal connections
i did i don’t see anything wrong with them
I noticed that In your scripts has following: if area.is_in_group(“shot.tscn”) or area.is_in_group(“Player.tscn”) …
You can check the projectile is in those groups or not, if not then the asteroid will not destroy.
But there are still another reasons can cause bug happen, you can try debug by yourself like the video says😎 :
i watched the video over and over but i still can’t figure out my problem according to the book it should work with what i have wrote but it’s not please someone out there is it me or has the book got it wrong