Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://www.youtube.com/watch?v=w2J_wG5oiNg&list=PLMj5RSRN1rwp0R01nByvvYUvffoEyStzk&index=2
- https://www.youtube.com/watch?v=mFOi6W7lohk&list=PLadYLGMfR6LqzKa4lhT1xjv8bBvA4WT8-&index=2
- https://www.codeproject.com/Articles/1029858/Making-a-D-Physics-Engine-The-Math
- https://github.com/PacktPublishing/Godot-Game-Engine-Projects/tree/master/Chapter%202%20-%20Coin%20Dash
- I made a coin scene and when the player collide with it the coin disappears and the score goes higher but it's not working.
- here is the coin code:
- extends Area2D
- signal e_grabbed
- func _on_coin_body_entered(body):
- if body.name == "player":
- emit_signal("e_grabbed")
- queue_free()
- and this is the main scene code:
- func spawn():
- var coin_scene = load("res://scenes/coin.tscn")
- randomize()
- var coin = coin_scene.instance()
- var random = Vector2(rand_range(30,230),-4)
- coin.set_position(random)
- coin.connect("e_grabbed", self, "_on_e_grabbed")
- $coins.add_child(coin)
- func _on_e_grabbed():
- print("grgrg")
- it doesn't print 'grgrg'
- signals
- asked 1 day ago in Projects by Shlopynoobnoob (32 points)
- Did you try adding a debugger to the _on_coin_body_entered(body) function and checking if the body entering is actually what you expect it to be? For example, you might have a player but the name is not matching 'player'.
- commented 1 day ago by tastyshrimp
- 1 Answer
- 0
- votes
- Ah, I see an issue. In your Coin.gd, you left queue_free() outside of the if loop.
- extends Area2D
- signal e_grabbed
- func _on_coin_body_entered(body):
- if body.name == "player":
- emit_signal("e_grabbed")
- queue_free()
- That's all I would do. If the system fusses, try putting the Player scene into a Group called "player", and change if body.name == "player" to if body.is_in_group("player").
- In mainscene.gd, I'd put randomize() into the _ready() function, and have var coin_scene = preload("res://scenes/coin.tscn") between the topmost function, and the extends line.
- Apologies if this is a bit of a mess.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement