FlyingDonut.gd 531 B

12345678910111213141516171819202122232425262728293031
  1. extends Spatial
  2. var fallspeed = 2
  3. var accel = 0.15
  4. var y_limit = - 20.0
  5. var sp = AudioStreamPlayer3D.new()
  6. func _ready():
  7. $Area.connect("body_entered",self,"_on_body_entered")
  8. sp.unit_size = 0.1
  9. sp.stream = preload("res://message.ogg")
  10. add_child(sp)
  11. sp.connect("finished",self,"queue_free")
  12. func _on_body_entered(body):
  13. print ("yum!")
  14. sp.play()
  15. visible = false
  16. fallspeed=-1
  17. accel=0
  18. func _process(delta):
  19. translate(fallspeed*delta*Vector3(0,-1,0))
  20. fallspeed+=accel
  21. if translation.y<=y_limit:
  22. queue_free()