Advertisement
otorp2

gd coin ex plus links

Dec 21st, 2019
518
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. https://www.youtube.com/watch?v=w2J_wG5oiNg&list=PLMj5RSRN1rwp0R01nByvvYUvffoEyStzk&index=2
  2.  
  3. https://www.youtube.com/watch?v=mFOi6W7lohk&list=PLadYLGMfR6LqzKa4lhT1xjv8bBvA4WT8-&index=2
  4.  
  5. https://www.codeproject.com/Articles/1029858/Making-a-D-Physics-Engine-The-Math
  6.  
  7. https://github.com/PacktPublishing/Godot-Game-Engine-Projects/tree/master/Chapter%202%20-%20Coin%20Dash
  8.  
  9.  
  10. 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.
  11.  
  12. here is the coin code:
  13.  
  14. extends Area2D
  15.  
  16. signal e_grabbed
  17.  
  18. func _on_coin_body_entered(body):
  19. if body.name == "player":
  20. emit_signal("e_grabbed")
  21. queue_free()
  22. and this is the main scene code:
  23.  
  24. func spawn():
  25. var coin_scene = load("res://scenes/coin.tscn")
  26. randomize()
  27. var coin = coin_scene.instance()
  28. var random = Vector2(rand_range(30,230),-4)
  29. coin.set_position(random)
  30. coin.connect("e_grabbed", self, "_on_e_grabbed")
  31. $coins.add_child(coin)
  32.  
  33. func _on_e_grabbed():
  34. print("grgrg")
  35. it doesn't print 'grgrg'
  36.  
  37. signals
  38. asked 1 day ago in Projects by Shlopynoobnoob (32 points)
  39.  
  40. 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'.
  41.  
  42. commented 1 day ago by tastyshrimp
  43. 1 Answer
  44. 0
  45. votes
  46. Ah, I see an issue. In your Coin.gd, you left queue_free() outside of the if loop.
  47.  
  48. extends Area2D
  49.  
  50. signal e_grabbed
  51.  
  52. func _on_coin_body_entered(body):
  53. if body.name == "player":
  54. emit_signal("e_grabbed")
  55. queue_free()
  56. 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").
  57.  
  58. 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.
  59.  
  60. Apologies if this is a bit of a mess.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement